using DeviceRepair.Api.Common;
using DeviceRepair.Api.CustomAttribute;
using DeviceRepair.DataAccess;
using DeviceRepair.Models;
using NLog;
using System;
using System.Web.Http;

namespace DeviceRepair.Api.Controllers
{
    [RoutePrefix("Api/TsSFC")]
    public class TsSFCController : CFController
    {
        private static readonly Logger log = LogManager.GetCurrentClassLogger();

        /// <summary>
        /// 判断设备是否禁用
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpGet, Route("GetTheEquipmentInMaintenance")]
        public IHttpActionResult GetTheEquipmentInMaintenance(int EquipmentID)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = 1, Message = "",Data = true };
            return Ok(apiResponseData);
        }

        /// <summary>
        /// 获取TsSFC用户权限
        /// </summary>
        /// <param name="UserGuid"></param>
        /// <returns></returns>
        [HttpGet, Route("GetTsSFCUserAuths"), HttpAuthorize]
        public IHttpActionResult GetTsSFCUserAuths(string UserGuid)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "接口调用出现错误！" };
            try
            {
                Guid userguid;
                if (Guid.TryParse(UserGuid, out userguid))
                {
                    apiResponseData = TsSFCAccess.Instance.GetUserAuths(userguid);
                }
                else
                {
                    throw new ArgumentException("传入的用户GUID编号不是GUID格式!");
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                apiResponseData.Code = -1;
                apiResponseData.Message = ex.Message;
            }

            return Ok(apiResponseData);
        }
    }
}