using Furion.JsonSerialization;
using YBEE.EQM.Core;

namespace YBEE.EQM.Application;

/// <summary>
/// 附件信息转换
/// </summary>
public class AttachmentMapper : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        // 机构数据项上报附件
        config.ForType<ExamOrgDataReport, ExamOrgDataReportOutput>().Map(d => d.AttachmentList, s => JSON.Deserialize<List<AttachmentItem>>(s.Attachments, null));
        // 特殊学生明细附件
        config.ForType<ExamSpecialStudent, ExamSpecialStudentOutput>().Map(d => d.AttachmentList, s => JSON.Deserialize<List<AttachmentItem>>(s.Attachments, null));
        // 缺测替补明细附件
        config.ForType<ExamAbsentReplace, ExamAbsentReplaceOutput>().Map(d => d.AttachmentList, s => JSON.Deserialize<List<AttachmentItem>>(s.Attachments, null));
        // 监测数据上报类型附件
        config.ForType<ExamDataReport, ExamDataReportOutput>().Map(d => d.AttachmentList, s => JSON.Deserialize<List<AttachmentItem>>(s.Attachments, null));


        config.ForType<ResourceFileOutput, AddAttachmentInput>().Map(d => d.SourceId, s => (int)s.SourceId)
                                                                .Map(d => d.FileId, s => s.Id)
                                                                .Map(d => d.ThumbFileId, s => s.ThumbResourceFile.Id)
                                                                ;
        config.ForType<ResourceFileOutput, AddExamOrgDataReportAttachmentInput>().Map(d => d.SourceId, s => (int)s.SourceId)
                                                                .Map(d => d.FileId, s => s.Id)
                                                                .Map(d => d.ThumbFileId, s => s.ThumbResourceFile.Id)
                                                                ;
    }
}
