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

namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
    /// <summary>
    /// 案件复提
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReSubmitController : ControllerBase
    {
        readonly ReSubmitApp _app;

        public ReSubmitController(ReSubmitApp app)
        {
            _app = app;
        }

        /// <summary>
        /// 案件复提
        /// </summary>
        /// <param name="originalcaseno">原始案件编号</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> SaveReSubmitInfo([FromBody] ReSubmitReq req)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                response = await _app.SaveReSubmitInfo(req.originalcaseno, req.remark,req.subjectkey);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return response;
        }

        /// <summary>
        /// 查询复提数据
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet]
        public async Task<Response<List<ReSubmit>>> LoadReSubmitDatas()
        {
            Response<List<ReSubmit>> response = new Response<List<ReSubmit>>();
            try
            {
                response = await _app.LoadReSubmitDatas();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return response;
        }
    }
}
