using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.BaseApp.Shape;
using OpenAuth.App.ServiceApp.DroneCaseInfoTaskManage;
using OpenAuth.App.ServiceApp.DroneCaseInfoTaskManage.Request;
using OpenAuth.App.ServiceApp.DroneCaseInfoTaskManage.Response;
using OpenAuth.App.ServiceApp.DroneCloudQuery;
using OpenAuth.App.ServiceApp.DroneCloudQueryManage.Request;
using OpenAuth.App.ServiceApp.Response;
using OpenAuth.Repository.Domain;

namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
    /// <summary>
    /// shp导入
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    class DroneCaseInfoTaskController : ControllerBase
    {
        private DroneCaseInfoTaskApp _app;

        public DroneCaseInfoTaskController(DroneCaseInfoTaskApp app)
        {
            _app = app;
        }

        /// <summary>
        ///添加案件截图任务 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<bool> AddCaseInfoTask(AddCaseinfoTaskReq req)
        {
            var response = new Response<bool>();
            if (string.IsNullOrEmpty(req.picihao))
                throw new Exception("批次号不能为空");
            try
            {
                response = _app.AddCaseInfoTask(req.caseinfoids, req.shplayerids,req.qianshixiang,req.houshixiang,req.picihao);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 获取需要查询的任务列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<DroneCaseInfoTask>>> LoadDroneCaseInfoTask()
        {
            return await _app.LoadDroneCaseInfoTask();
        }

        /// <summary>
        /// 添加数据查询结果
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdateDroneCaseInfo(DroneCaseInfoTaskRes req)
        {
            var response = new Response<bool>();
            try
            {
                response = await _app.UpdateDroneCaseInfo(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 添加数据查询结果--矿产
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdateDroneCaseInfoMinerals(DroneCaseInfoTaskRes req)
        {
            var response = new Response<bool>();
            try
            {
                response = await _app.UpdateDroneCaseInfoMinerals(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }


        /// <summary>
        /// 根据批次号分页获取列表数据
        /// </summary>
        /// <param name="picihao">批次号</param>
        /// <param name="laiyuan">图斑来源</param>
        /// <param name="begintime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="page">当前页</param>
        /// <param name="limit">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<DroneCaseInfoImport>>>> LoadDataBaseInfo(string picihao,string laiyuan, DateTime? begintime, DateTime? endtime, int page = 1, int limit = 15)
        {
            return await _app.LoadCaseImportInfoBypicihao(picihao,laiyuan,begintime,endtime, page, limit);
        }

        /// <summary>
        /// 查询图层信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<DroneLayerInfo>>> LoadLayerInfo()
        {
            return await _app.LoadLayerInfo();
        }

        /// <summary>
        /// shp导入
        /// </summary>
        /// <param name="zipFilePath"></param>
        /// <param name="srid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<string>> ImportCaseInfoShpData(string zipFilePath, string srid,string subjectname)
        {
            var result = new Response<string>();
            try
            {
                result = await _app.ImportCaseInfoShpData(zipFilePath, srid,subjectname);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }


        /// <summary>
        /// 矿产shp导入
        /// </summary>
        /// <param name="zipFilePath"></param>
        /// <param name="srid"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<string>> ImportMineralShpData(string zipFilePath, string srid, string subjectname)
        {
            var result = new Response<string>();
            try
            {
                result = await _app.ImportMineralShpData(zipFilePath, srid, subjectname);
            }
            catch (Exception ex)
            {
                result.Code = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return result;
        }

        /// <summary>
        ///添加前时像后时像信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public Response<bool> AddTubanshixiang(List<DroneTuBanshixiang> req)
        {
            var response = new Response<bool>();
            try
            {
                response = _app.AddTubanshixiang(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<List<DroneTuBanshixiang>>> LoadTuBanshixiang()
        {
            return await _app.LoadTuBanshixiang();
        }

        /// <summary>
        /// 更新进度值
        /// </summary>
        /// <param name="id"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Response<bool> UpdateDroneCaseInfoTask(string id,int rate)
        {
            var response = new Response<bool>();
            try
            {
                response = _app.UpdateDroneCaseInfoTask(id,rate);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 查询任务信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<DroneCaseInfoTask>> LoadDroneCaseInfobyid(string id)
        {
            return await _app.LoadDroneCaseInfobyid(id);
        }

        /// <summary>
        /// 根据用户获取需要查询的任务列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<DroneCaseInfoTask>>> LoadDroneCaseInfoTaskByUser()
        {
            return await _app.LoadDroneCaseInfoTaskByUser();
        }

        /// <summary>
        /// 查询最后一次导入数据
        /// </summary>
        /// <param name="subjectname">专题名称</param>
        /// <param name="page">当前页</param>
        /// <param name="limit">每页条数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<string>> LoadCaseImportInfoLast(string subjectname, int page = 1, int limit = 15)
        {
            return await _app.LoadCaseImportInfoLast(subjectname,page, limit);
        }


        /// <summary>
        /// 导入数据--不截图
        /// </summary>
        /// <param name="picihao">批次号</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdateDroneCaseInfoT(string picihao)
        {
            var response = new Response<bool>();
            try
            {
                response = await _app.UpdateDroneCaseInfoT(picihao);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 导入数据--矿产--不截图
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdateDroneCaseInfoMineralsT(string picihao)
        {
            var response = new Response<bool>();
            try
            {
                response = await _app.UpdateDroneCaseInfoMineralsT(picihao);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        [HttpPost]
        public async Task<Response<bool>> ImportCaseInfoShpDataSsny(string zipFilePath, string srid)
        {
            var response = new Response<bool>();
            try
            {
                response = await _app.ImportCaseInfoShpDataSsny(zipFilePath, srid);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
    }
}
