using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp.FireManagement;
using OpenAuth.App.ServiceApp.FireManagement.Request;
using OpenAuth.Repository.Domain.FireManagement;

namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
{
    /// <summary>
    /// 网格
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FireGridController : ControllerBase
    {
        private readonly FireGridApp _app;

        public FireGridController(FireGridApp app)
        {
            _app = app;
        }
        /// <summary>
        /// 添加打卡点
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddCheckPoint(CheckPointReq info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.AddCheckPoint(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取打卡点列表
        /// </summary>
        /// <param name="pointName"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<dynamic>>>> GetCheckPointList(string pointName, int pageIndex, int pageSize)
        {
            Response<PageInfo<List<dynamic>>> response = new Response<PageInfo<List<dynamic>>>();
            try
            {
                return await _app.GetCheckPointList(pointName, pageIndex, pageSize);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 删除打卡点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> DeleteCheckPoint(long id)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.DeleteCheckPoint(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 编辑打卡点
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> EditCheckPoint(CheckPointReq info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.EditCheckPoint(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取单个打卡点
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<CheckPointReq>> GetSingleCheckPoint(long id)
        {
            Response<CheckPointReq> response = new Response<CheckPointReq>();
            try
            {
                return await _app.GetCheckPointById(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取打卡记录列表
        /// </summary>
        /// <param name="userId">人员ID</param>
        /// <param name="beginTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<dynamic>>>> GetClockOnList(long userId, DateTime beginTime, DateTime endTime, int pageIndex, int pageSize)
        {
            Response<PageInfo<List<dynamic>>> response = new Response<PageInfo<List<dynamic>>>();
            try
            {
                return await _app.GetClockOnList(userId, beginTime, endTime, pageIndex, pageSize);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
    }
}
