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

namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FirePatrolController : ControllerBase
    {
        private readonly FirePatrolApp _app;

        public FirePatrolController(FirePatrolApp app)
        {
            _app = app;
        }
        /// <summary>
        /// 获取人员巡查轨迹
        /// </summary>
        /// <param name="id"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<UserPatrolInfoResp>>> GetPatrolInfoByUserId(long id, DateTime beginTime, DateTime endTime)
        {
            Response<List<UserPatrolInfoResp>> response = new Response<List<UserPatrolInfoResp>>();
            try
            {
                return await _app.GetPatrolInfoByUserId(id, beginTime, endTime);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 根据人员id获取巡查坐标
        /// </summary>
        /// <param name="id"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FmUserPointHistory>>> GetPatrolPointByTime(long id, DateTime beginTime, DateTime endTime)
        {
            Response<List<FmUserPointHistory>> response = new Response<List<FmUserPointHistory>>();
            try
            {
                return await _app.LoadPatrolPointByTime(id, beginTime, endTime);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取人员范围
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> GetUserRange(string phone)
        {
            Response<dynamic> response = new Response<dynamic>();
            try
            {
                return await _app.GetUserRange(phone);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 巡查信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FmUserPointHistory>>> GetPatrolPointByTimeSubsection(long id, DateTime beginTime, DateTime endTime)
        {
            Response<List<FmUserPointHistory>> response = new Response<List<FmUserPointHistory>>();
            try
            {
                return await _app.LoadPatrolPointByTimeSubsection(id, beginTime, endTime);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 新版根据用户ID查询巡查信息
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="beginTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<PatrolinfoResp>>> LoadPatrolInfoByUserIdNew(long userId, DateTime beginTime, DateTime endTime)
        {
            Response<List<PatrolinfoResp>> response = new Response<List<PatrolinfoResp>>();
            try
            {
                return await _app.LoadPatrolInfoByUserIdNew(userId, beginTime, endTime);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

    }
}
