using System.Collections.Generic;
using System.Web.Http;
using FactorySystemBll;
using FactorySystemCommon;
using FactorySystemModel.BusinessModel;
using FactorySystemModel.ResponseModel;

namespace FactorySystemApi.Controllers
{
    /// <summary>
    /// 操作日志
    /// </summary>
    [UserLoginFilter]
    public class OperateLogController : ApiController
    {
        private readonly OperateLogBll _operateLogBll = new OperateLogBll();

        /// <summary>
        /// 获取分页
        /// </summary>
        [HttpPost]
        public ApiResult GetPageList(Dictionary<string, object> inParam)
        {
            var apiResult = new ApiResult();
            return ExceptionHelper.TryReturnException(() =>
            {
                apiResult.Data = new
                {
                    List = _operateLogBll.GetPageList(inParam, out int totalCount),
                    Total = totalCount
                };
            }, apiResult, Request);
        }

        /// <summary>
        /// 保存操作日志
        /// </summary>
        [HttpPost]
        public ApiResult Save(Dictionary<string, object> inParams)
        {
            var teamId = int.Parse(inParams["teamId"].ToString());
            var type = int.Parse(inParams["type"].ToString());
            var desc = inParams["desc"].ToString();
            var apiResult = new ApiResult();
            return ExceptionHelper.TryReturnException(() =>
            {
                if (Request.Properties["token"] is ApiAuthInfo user)
                {
                    OperateLogBll.Add(teamId, type, desc, user.FID);
                }
            }, apiResult, Request);
        }

    }
}
