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.FmPreventionPlanManage;
using OpenAuth.App.ServiceApp.FmPreventionPlanManage.Request;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Domain.FireManagement;

namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
{
    /// <summary>
    /// 防火应急预案模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FmPreventionPlanController : ControllerBase
    {
        private readonly FmPreventionPlanApp _app;

        public FmPreventionPlanController(FmPreventionPlanApp app)
        {
            _app = app;
        }

        /// <summary>
        /// 分页查询防火应急预案列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<FmPreventionplan>>>> GetPreventionplanPageList([FromQuery] FmPreventionplanReq req)
        {
            Response<PageInfo<List<FmPreventionplan>>> response = new Response<PageInfo<List<FmPreventionplan>>>();
            try
            {
                return await _app.GetPreventionplanPageList(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }


        /// <summary>
        /// 查询应急预案详情
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<FmPreventionplan>> LoadClueInfoById(string id)
        {
            Response<FmPreventionplan> response = new Response<FmPreventionplan>();
            try
            {
                return await _app.LoadClueInfoById(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]
        public async Task<Response<bool>> AddPreventionplan(PrePlanAddReq info)
        {
            Response<bool> response = new();
            try
            {
                return await _app.AddPreventionplan(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 删除预案
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeletePreventionplan(string id)
        {
            Response<bool> response = new();
            try
            {
                return await _app.DeletePreventionplan(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

    }
}
