package com.smppw.modaq.domain.dto.report;

import cn.hutool.core.util.StrUtil;
import com.smppw.modaq.domain.entity.report.ReportFinancialIndicatorsDO;
import lombok.Getter;
import lombok.Setter;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Setter
@Getter
public class ReportFinancialIndicatorsDTO extends BaseReportLevelDTO<ReportFinancialIndicatorsDO> {
    /**
     * 年度
     */
    private String yearly;
    /**
     * 期末基金净资产
     */
    private String assetNet;
    /**
     * 报告期期末单位净值
     */
    private String nav;
    /**
     * 本期利润
     */
    private String profit;
    /**
     * 本期已实现收益
     */
    private String realizedIncome;
    /**
     * 期末可供分配利润
     */
    private String undistributedProfit;
    /**
     * 期末可供分配基金份额利润
     */
    private String undistributedShareProfit;
    /**
     * 基金份额累计净值增长率
     */
    private String shareNavRet;

    public ReportFinancialIndicatorsDTO() {
        super();
    }

    public ReportFinancialIndicatorsDTO(Integer fileId) {
        super(fileId);
    }

    public ReportFinancialIndicatorsDTO(Integer fileId, String level) {
        super(fileId, level);
    }

    @Override
    public ReportFinancialIndicatorsDO toEntity() {
        ReportFinancialIndicatorsDO entity = new ReportFinancialIndicatorsDO();
        entity.setFileId(this.getFileId());
        entity.setLevel(this.getLevel());
        entity.setFundAssetSize(this.toBigDecimal(this.assetNet));
        entity.setNav(this.toBigDecimal(this.nav));
        entity.setProfit(this.toBigDecimal(this.profit));
        entity.setRealizedIncome(this.toBigDecimal(this.realizedIncome));
        entity.setUndistributedProfit(this.toBigDecimal(this.undistributedProfit));
        if (StrUtil.isNotBlank(this.yearly)) {
            Matcher matcher = Pattern.compile("\\d+").matcher(this.yearly);
            if (matcher.find()) {
                entity.setEndDate(Integer.parseInt(matcher.group()));
            }
        }
        return entity;
    }

    @Override
    public String toString() {
        return "{" +
                super.toString() +
                ", yearly=" + yearly +
                ", assetNet=" + assetNet +
                ", nav=" + nav +
                ", profit=" + profit +
                ", undistributedProfit=" + undistributedProfit +
                ", realizedIncome=" + realizedIncome +
                ", undistributedShareProfit=" + undistributedShareProfit +
                ", shareNavRet=" + shareNavRet +
                '}';
    }
}
