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

import com.smppw.modaq.domain.dto.report.LetterReportData;
import com.smppw.modaq.domain.dto.report.ReportFundTransactionDTO;
import com.smppw.modaq.domain.dto.report.ReportInvestorInfoDTO;
import com.smppw.modaq.domain.mapper.report.ReportBaseInfoMapper;
import com.smppw.modaq.domain.mapper.report.ReportFundInfoMapper;
import com.smppw.modaq.domain.mapper.report.ReportFundTransactionMapper;
import com.smppw.modaq.domain.mapper.report.ReportInvestorInfoMapper;
import org.springframework.stereotype.Component;

@Component(ReportWriterConstant.WRITER_LETTER)
public class LetterReportWriter extends AbstractReportWriter<LetterReportData> {
    private final ReportInvestorInfoMapper investorInfoMapper;
    private final ReportFundTransactionMapper fundTransactionMapper;

    public LetterReportWriter(ReportBaseInfoMapper baseInfoMapper, ReportFundInfoMapper fundInfoMapper,
                              ReportInvestorInfoMapper investorInfoMapper, ReportFundTransactionMapper fundTransactionMapper) {
        super(baseInfoMapper, fundInfoMapper);
        this.investorInfoMapper = investorInfoMapper;
        this.fundTransactionMapper = fundTransactionMapper;
    }

    @Override
    protected void writeExtData(LetterReportData reportData) {
        ReportInvestorInfoDTO investorInfo = reportData.getInvestorInfo();
        if (investorInfo != null) {
            this.investorInfoMapper.insert(investorInfo.toEntity());
        }
        ReportFundTransactionDTO fundTransaction = reportData.getFundTransaction();
        if (fundTransaction != null) {
            this.fundTransactionMapper.insert(fundTransaction.toEntity());
        }
    }
}
