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

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

        /// <summary>
        /// 获取tag数据
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        [HttpPost, Route("GetDatas"), HttpAuthorize]
        public IHttpActionResult GetDatas(TagRecordFilter filter)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "接口调用失败！" };
            try
            {
                GetParams();
                apiResponseData = TagAccess.Instance.GetDatas(filter, OperationInfo.OperatorCode);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                apiResponseData.Code = -1;
                apiResponseData.Message = ex.Message.ToString();
            }
            return Ok(apiResponseData);
        }

        /// <summary>
        /// 数据新增
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        [HttpPost,Route("Creat"),HttpAuthorize]
        public IHttpActionResult Creat(TagRecordInfo tag)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "接口调用失败！" };
            try
            {
                base.GetParams();
                apiResponseData = TagAccess.Instance.Creat(tag, base.OperationInfo);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                apiResponseData.Code = -1;
                apiResponseData.Message = ex.Message.ToString();
            }
            return Ok(apiResponseData);
        }

        /// <summary>
        /// 接受/维修
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        [HttpPost,Route("Receipt"),HttpAuthorize]
        public IHttpActionResult Receipt(TagRecordInfo tag)
        {
            APIResponseData apiResponseData = new APIResponseData { Code = -1, Message = "接口调用失败！" };
            try
            {
                base.GetParams();
                apiResponseData = TagAccess.Instance.Receipt(tag, base.OperationInfo);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                apiResponseData.Code = -1;
                apiResponseData.Message = ex.Message.ToString();
            }
            return Ok(apiResponseData);
        }
    }
}