using YBEE.EQM.Core;

namespace YBEE.EQM.Application;

/// <summary>
/// 监测机构上报类型服务
/// </summary>
[ApiDescriptionSettings(Name = "exam-org-data-report")]
[Route("exam/org/data/report")]
public class ExamOrgDataReportAppService : IDynamicApiController
{
    private readonly IExamOrgDataReportService _examOrgDataReportService;
    private readonly IResourceFileService _resourceFileService;

    public ExamOrgDataReportAppService(IExamOrgDataReportService examOrgDataReportService, IResourceFileService resourceFileService)
    {
        _examOrgDataReportService = examOrgDataReportService;
        _resourceFileService = resourceFileService;
    }

    /// <summary>
    /// 提交上报
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task Submit(SubmitExamOrgDataReportInput input)
    {
        await _examOrgDataReportService.Submit(input);
    }

    /// <summary>
    /// 退回机构上报
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task ReportReject(BaseId input)
    {
        await _examOrgDataReportService.ReportReject(input);
    }

    /// <summary>
    /// 上传佐证材料
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [RequestSizeLimit(1024 * 1024 * 20)]
    [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
    public async Task UploadAttachment([FromForm] UploadExamOrgDataReportAttachmentInput input)
    {
        var rfile = await _resourceFileService.Upload(input);
        var addParams = rfile.Adapt<AddExamOrgDataReportAttachmentInput>();
        addParams.Type = input.DataReportType;
        addParams.ExamPlanId = input.ExamPlanId;
        //addParams.SourceId = (int)input.SourceId;
        //addParams.FileId = rfile.Id;
        //addParams.ThumbFileId = rfile.ThumbResourceFile?.Id;
        await _examOrgDataReportService.AddAttachment(addParams);
    }
    /// <summary>
    /// 删除特殊学生佐证材料
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task DelAttachment(DeleteAttachmentInput input)
    {
        await _examOrgDataReportService.DelAttachment(input);
    }
    /// <summary>
    /// 获取监测机构上报类型列表
    /// </summary>
    /// <param name="examPlanId"></param>
    /// <param name="sysOrgId">机构ID</param>
    /// <returns></returns>
    public async Task<List<ExamOrgDataReportUnionOutput>> GetListByExamPlanId([FromQuery][Required] int examPlanId, short? sysOrgId = null)
    {
        return await _examOrgDataReportService.GetListByExamPlanId(examPlanId, sysOrgId);
    }
    /// <summary>
    /// 根据监测计划ID和上报类型获取机构上报信息
    /// </summary>
    /// <param name="type">上报类型</param>
    /// <param name="examPlanId">监测计划ID</param>
    /// <param name="sysOrgId">机构ID</param>
    /// <returns></returns>
    public async Task<ExamOrgDataReportUnionOutput> GetByTypeExamPlanId([FromQuery][Required] DataReportType type, [FromQuery][Required] int examPlanId, short? sysOrgId = null)
    {
        return await _examOrgDataReportService.GetByTypeExamPlanId(type, examPlanId, sysOrgId);
    }
    /// <summary>
    /// 分页查询机构上报类型列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task<PageResult<ExamPlanOrgDataReportOutput>> QueryPageList(ExamOrgDataReportPageInput input)
    {
        return await _examOrgDataReportService.QueryPageList(input);
    }

    //[HttpGet]
    //[AllowAnonymous]
    //public async Task RefreshFileSize()
    //{
    //    await _examOrgDataReportService.RefreshFileSize();
    //}
}
