using YBEE.EQM.Core;

namespace YBEE.EQM.Application;

/// <summary>
/// 试卷管理服务
/// </summary>
[ApiDescriptionSettings(Name = "exam-paper")]
[Route("exam/paper")]
public class ExamPaperAppService(IExamPaperService examPaperService) : IDynamicApiController
{
    private readonly IExamPaperService _examPaperService = examPaperService;

    /// <summary>
    /// 按监测计划初始化试卷
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [UnitOfWork]
    public async Task BatchInit(ExamPaperBatchInitInput input)
    {
        await _examPaperService.BatchInit(input);
    }
    /// <summary>
    /// 分配双向细目表编制人
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task AssignTwclWriter(AssignExamPaperWriterInput input)
    {
        await _examPaperService.AssignTwclWriter(input);
    }
    /// <summary>
    /// 分配问题建议撰写人
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task AssignSuggestionWriter(AssignExamPaperWriterInput input)
    {
        await _examPaperService.AssignSuggestionWriter(input);
    }
    /// <summary>
    /// 根据ID获取试卷详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public async Task<ExamPaperOutput> GetById(int id)
    {
        return await _examPaperService.GetById(id);
    }
    /// <summary>
    /// 根据监测计划ID获取试卷列表（管理端）
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <returns></returns>
    public async Task<List<ExamPaperLiteOutput>> GetListByExamPlanId(int examPlanId)
    {
        return await _examPaperService.GetListByExamPlanId(examPlanId);
    }
    /// <summary>
    /// 获取双向细目表监测计划列表（管理端）
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<PageResult<ExamPaperTodoPlanOutput>> QueryExamPlanPageList(ExamPlanPageInput input)
    {
        return await _examPaperService.QueryExamPlanPageList(input);
    }
    /// <summary>
    /// 导出TQES导入文件格式文件包
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <returns></returns>
    /// <exception cref="Exception"></exception>
    public async Task<IActionResult> ExportTqesFile([Required] int examPlanId)
    {
        var (fileName, fileBytes) = await _examPaperService.ExportTqesFile(examPlanId);
        return new FileContentResult(fileBytes, "application/octet-stream")
        {
            FileDownloadName = fileName,
        };
    }

    #region 编撰者
    /// <summary>
    /// 分页查询编撰人监测计划列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<PageResult<ExamPaperTodoPlanOutput>> QueryWriterExamPlanPageList(ExamPaperExamPlanPageInput input)
    {
        return await _examPaperService.QueryWriterExamPlanPageList(input);
    }
    /// <summary>
    /// 根据监测计划ID获取待处理试卷列表
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <param name="writerType"></param>
    /// <returns></returns>
    public async Task<List<ExamPaperLiteOutput>> GetWriterListByExamPlanId([Required] int examPlanId, [Required] ExamPaperWriterType writerType)
    {
        return await _examPaperService.GetWriterListByExamPlanId(examPlanId, writerType);
    }

    /// <summary>
    /// 保存问题建议
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task SaveSuggestion(SaveExamPaperSuggestion input)
    {
        await _examPaperService.SaveSuggestion(input);
    }
    /// <summary>
    /// 提交双向细目表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task SubmitTwcl(BaseId input)
    {
        await _examPaperService.SubmitTwcl(input);
    }
    /// <summary>
    /// 提交问题建议
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task SubmitSuggestion(BaseId input)
    {
        await _examPaperService.SubmitSuggestion(input);
    }
    #endregion


}
