package com.smppw.modaq.application.components.report.parser.ai;

import com.smppw.modaq.application.components.report.parser.ReportParserConstant;
import com.smppw.modaq.common.exception.ReportParseException;
import com.smppw.modaq.domain.dto.report.ReportBaseInfoDTO;
import com.smppw.modaq.domain.dto.report.ReportFundInfoDTO;
import com.smppw.modaq.domain.dto.report.ReportParserParams;
import com.smppw.modaq.domain.dto.report.WeeklyReportData;
import com.smppw.modaq.domain.mapper.EmailFieldMappingMapper;
import org.springframework.stereotype.Component;

/**
 * 管理人周报AI解析器
 */
@Component(ReportParserConstant.PARSER_AI_WEEKLY)
public class AIWeeklyReportParser extends AbstractAIReportParser<WeeklyReportData> {
    public AIWeeklyReportParser(EmailFieldMappingMapper fieldMappingMapper) {
        super(fieldMappingMapper);
    }

    @Override
    protected String prompt() {
        return """
                识别文件中的基金名称、基金管理人、产品代码和报告日期，产品代码的正则表达式是`S[A-Z0-9]{5}`；
                如果无法识别就返回空字符，结果用json返回，json中不要注释
                """;
    }

    @Override
    protected boolean isSupportAIParse() {
        return true;
    }

    @Override
    protected WeeklyReportData parseExtInfoAndSetData(ReportBaseInfoDTO reportInfo,
                                                      ReportFundInfoDTO fundInfo) throws ReportParseException {
//        Object contact = this.allInfoMap.get("联系人信息");
//        if (ObjUtil.isNotEmpty(contact)) {
//            reportInfo.setWithContacts(true);
//        }
        return new WeeklyReportData(reportInfo, fundInfo);
    }

    @Override
    protected ReportFundInfoDTO buildFundInfo(ReportParserParams params) {
        return this.buildDto(params.getFileId(), ReportFundInfoDTO.class, this.allInfoMap);
    }
}
