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

namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
    /// <summary>
    /// 管理员任务管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AdminTaskManageController : ControllerBase
    {
        readonly AdminTaskManageApp _app;
        public AdminTaskManageController(AdminTaskManageApp app)
        {
            _app = app;
        }
        /// <summary>
        /// 管理员获取任务列表
        /// </summary>
        /// <param name="taskName"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<InsTaskForAdminResp>>>> GteTaskListForAdmin(string taskName, int page, int limit)
        {
            Response<PageInfo<List<InsTaskForAdminResp>>> response = new Response<PageInfo<List<InsTaskForAdminResp>>>();
            try
            {
                return await _app.GteTaskListForAdmin(taskName, page, limit);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<string>> AddTask(InsTaskReq req)
        {
            Response<string> response = new Response<string>();
            try
            {
                return await _app.AddTask(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<string>> DeleteTask(string id)
        {
            Response<string> response = new Response<string>();
            try
            {
                return await _app.DeleteTask(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<string>> EditTask(InsTaskReq req)
        {
            Response<string> response = new Response<string>();
            try
            {
                return await _app.EditTask(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取单个任务信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<InsTaskReq>> GteTaskById(string id)
        {
            Response<InsTaskReq> response = new Response<InsTaskReq>();
            try
            {
                return await _app.GteTaskById(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 选择AI解译成果
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<AiShpForTaskResp>>> GteAiShp()
        {
            Response<List<AiShpForTaskResp>> response = new Response<List<AiShpForTaskResp>>();
            try
            {
                return await _app.GteAiShp();
            }
            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<AreaGroup>>> GteTif()
        {
            Response<List<AreaGroup>> response = new Response<List<AreaGroup>>();
            try
            {
                return await _app.GteTif();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
    }
}
