package com.smppw.modaq.application.components.report.writer;

import cn.hutool.core.collection.CollUtil;
import com.smppw.modaq.domain.dto.report.MonthlyReportData;
import com.smppw.modaq.domain.dto.report.ReportNetReportDTO;
import com.smppw.modaq.domain.entity.report.ReportNetReportDO;
import com.smppw.modaq.domain.mapper.report.ReportBaseInfoMapper;
import com.smppw.modaq.domain.mapper.report.ReportFundInfoMapper;
import com.smppw.modaq.domain.mapper.report.ReportNetReportMapper;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

@Component(ReportWriterConstant.WRITER_MONTHLY)
public class MonthlyReportWriter extends AbstractReportWriter<MonthlyReportData> {
    private final ReportNetReportMapper netReportMapper;

    public MonthlyReportWriter(ReportBaseInfoMapper baseInfoMapper,
                               ReportFundInfoMapper fundInfoMapper,
                               ReportNetReportMapper netReportMapper) {
        super(baseInfoMapper, fundInfoMapper);
        this.netReportMapper = netReportMapper;
    }

    @Override
    protected void writeExtData(MonthlyReportData reportData) {
        List<ReportNetReportDTO> netReport = reportData.getNetReport();
        if (CollUtil.isNotEmpty(netReport)) {
            List<ReportNetReportDO> entityList = netReport.stream()
                    .map(ReportNetReportDTO::toEntity).collect(Collectors.toList());
            this.netReportMapper.insert(entityList);
        }
    }
}
