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.MonthlyReportData;
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.mapper.EmailFieldMappingMapper;
import org.springframework.stereotype.Component;

@Component(ReportParserConstant.PARSER_AI_MONTHLY)
public class AIMonthlyReportParser extends AbstractAIReportParser<MonthlyReportData> {
    public AIMonthlyReportParser(EmailFieldMappingMapper fieldMappingMapper) {
        super(fieldMappingMapper);
    }

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

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

    @Override
    protected MonthlyReportData parseExtInfoAndSetData(ReportBaseInfoDTO reportInfo,
                                                       ReportFundInfoDTO fundInfo) throws ReportParseException {
//        Object contact = this.allInfoMap.get("联系人信息");
//        if (ObjUtil.isNotEmpty(contact)) {
//            // 有联系人就不要净值数据了
//            reportInfo.setWithContacts(true);
//        }
        // AI 就不解析净值数据了
//        List<ReportNetReportDTO> dtos = ListUtil.list(true);
//        for (Map.Entry<String, Object> entry : this.allInfoMap.entrySet()) {
//            Object netInfo = entry.getValue();
//            if (netInfo == null) {
//                continue;
//            }
//            Map<String, Object> netInfoMap = (Map<String, Object>) netInfo;
//            ReportNetReportDTO dto = this.buildDto(reportInfo.getFileId(), ReportNetReportDTO.class, netInfoMap);
//            if (dto == null) {
//                continue;
//            }
//            dto.setLevel(ReportParseUtils.matchFundLevel(entry.getKey()));
//            dtos.add(dto);
//        }
//        reportData.setNetReport(dtos);
        return new MonthlyReportData(reportInfo, fundInfo);
    }

    @Override
    protected ReportFundInfoDTO buildFundInfo(ReportParserParams params) {
//        // 获取并移除基金概况信息
//        Object fundInfo = this.allInfoMap.get("基金概况");
//        if (fundInfo == null) {
//            throw new ReportParseException(ReportParseStatus.PARSE_FUND_INFO_FAIL, params.getFilename());
//        }
//        Map<String, Object> fundInfoMap = (Map<String, Object>) fundInfo;
        return this.buildDto(params.getFileId(), ReportFundInfoDTO.class, this.allInfoMap);
    }
}
