using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.Excel;
using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.App.ServiceApp.MiManager.Response;
using OpenAuth.App.ServiceApp.MiManager.Resquest;
using OpenAuth.Repository.Domain;
using Org.BouncyCastle.Bcpg.OpenPgp;

namespace OpenAuth.WebApi.Controllers
{
    /// <summary>
    /// 打卡信息
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MiPunchRecordController : ControllerBase
    {
        private readonly MiPunchRecordApp _app;
        public MiPunchRecordController(MiPunchRecordApp app)
        {
            _app = app;
        }

        #region 查询

        #region 分页
        /// <summary>
        /// 分页
        /// </summary>
        [HttpGet]
        public async Task<Response<PageInfo<List<dynamic>>>> LoadAllPage([FromQuery] MiPuchLoadreq request)
        {
            var result = new Response<PageInfo<List<dynamic>>>();
            try
            {
                result = await _app.LoadAllPage(request);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }

        #endregion

        #region 实体
        /// <summary>
        /// 实体
        /// </summary>
        [HttpGet]
        public async Task<Response<MiPuchRecordRes>> Get(string id)
        {
            var result = new Response<MiPuchRecordRes>();
            try
            {
                result =await _app.Get(id);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion
        #endregion

        #region 增删改

        #region 添加
        /// <summary>
        /// 添加
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Add(MiPuchRecordReq model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Add(model);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        #region 修改
        /// <summary>
        /// 修改
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Update(MiPuchRecordReq model)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Update(model);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        [HttpPost]
        public async Task<Response<bool>> Delete(List<string> models)
        {
            var result = new Response<bool>();
            try
            {
                result = await _app.Delete(models);

            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }
        #endregion
        #endregion
    }
}