namespace YBEE.EQM.Application;

/// <summary>
/// 校考成绩上报管理服务
/// </summary>
[ApiDescriptionSettings(Name = "exam-org-score-report")]
[Route("exam/org/score/report")]
public class ExamOrgScoreReportAppService(IExamOrgScoreReportService examOrgScoreReportService) : IDynamicApiController
{
    private readonly IExamOrgScoreReportService _examOrgScoreReportService = examOrgScoreReportService;

    /// <summary>
    /// 上传校考成绩
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [RequestSizeLimit(1024 * 1024 * 20)]
    [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
    public async Task<UploadExamOrgScoreReportOutput> Upload([FromForm] UploadExamOrgScoreReportInput input)
    {
        return await _examOrgScoreReportService.Upload(input);
    }
    /// <summary>
    /// 查询某科目校考成绩上报数据
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<ExamOrgScoreReportOutput> QueryOne(QueryExamOrgScoreReportInput input)
    {
        return await _examOrgScoreReportService.QueryOne(input);
    }
    /// <summary>
    /// 获取机构校考上报明细列表
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <returns></returns>
    public async Task<List<ExamOrgScoreReportItem>> GetListByExamPlanId(int examPlanId)
    {
        return await _examOrgScoreReportService.GetListByExamPlanId(examPlanId);
    }
    ///// <summary>
    ///// 删除
    ///// </summary>
    ///// <param name="input"></param>
    ///// <returns></returns>
    //public async Task Del(DeleteAttachmentInput input)
    //{
    //    await _examOrgScoreReportService.Del(input);
    //}


    /// <summary>
    /// 合并学校上报小题分
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <returns></returns>
    public async Task<IActionResult> MergeMinorScore(int examPlanId)
    {
        var (fileName, fileBytes) = await _examOrgScoreReportService.MergeMinorScore(examPlanId);
        return new FileContentResult(fileBytes, "application/octet-stream")
        {
            FileDownloadName = fileName,
        };
    }
}
