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;
using System.Threading.Tasks;

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

        public FireCodeHController(FireCodeH5App app)
        {
            _app = app;
        }
        /// <summary>
        /// 添加进出山记录
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddEnteringInfo(FmEnteringInfo info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.AddEnteringInfo(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 根据手机号查询登记过的人员信息
        /// </summary>
        /// <param name="pointName"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<dynamic>>>> LoadNameInfoByPhone(string phone, int page, int limit)
        {
            Response<PageInfo<List<dynamic>>> response = new Response<PageInfo<List<dynamic>>>();
            try
            {
                return await _app.LoadNameInfoByPhone(phone, page, limit);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取站点信息
        /// </summary>
        /// <param name="siteId"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<dynamic>> GetSiteInfo(long siteId)
        {
            Response<dynamic> response = new Response<dynamic>();
            try
            {
                return await _app.GetSiteInfo(siteId);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        [HttpGet]
        [AllowAnonymous]
        public async Task GetFireInfo()
        {
            await _app.GetFireInfoAsync();
        }
        //[HttpGet]
        //[AllowAnonymous]
        //public async Task GetToken()
        //{
        //    await _app.GetToken();
        //}
    }
}
