using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp.Task;
using OpenAuth.App.ServiceApp.Task.Request;
using OpenAuth.App.ServiceApp.Task.Response;

namespace OpenAuth.WebApi.Controllers.ServiceControllers.Task;

/// <summary>
/// 个人任务
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class PersonTaskController : ControllerBase
{
    private readonly PersonTaskApp _app;

    public PersonTaskController(PersonTaskApp app)
    {
        _app = app;
    }

    /// <summary>
    /// 任务列表
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<InsTaskExtend>>>> Load([FromQuery] PersonTaskQuery req)
    {
        return await _app.Load(req);
    }

    /// <summary>
    /// 任务详情
    /// </summary>
    /// <param name="taskGroupId"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<InsTaskExtend>> GetTaskDetail(string taskGroupId)
    {
        return await _app.GetTaskDetail(taskGroupId);
    }

    /// <summary>
    /// 提交任务
    /// </summary>
    /// <param name="taskGroupId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> SubmitTask([FromBody] PersonTaskOp req)
    {
        return await _app.SubmitTask(req.TaskGroupId, req.Remark);
    }

    /// <summary>
    /// 退回任务
    /// </summary>
    /// <param name="taskGroupId"></param>
    /// <param name="remark"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> ReturnTask([FromBody] PersonTaskOp req)
    {
        return await _app.ReturnTask(req.TaskGroupId, req.Remark);
    }
}