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

import com.smppw.modaq.application.components.ReportParseUtils;
import com.smppw.modaq.domain.entity.report.ReportFundInfoDO;
import com.smppw.modaq.infrastructure.util.DateUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

/**
 * @author wangzaijun
 * @date 2024/9/26 16:47
 * @description 报告基金基本信息
 */
@Setter
public class ReportFundInfoDTO extends BaseReportDTO<ReportFundInfoDO> {
    /**
     * 基金的名称
     */
    private String fundName;

    /**
     * 基金的唯一识别代码
     */
    private String fundCode;

    /**
     * 基金管理人的名称
     */
    @Getter
    private String companyName;

    /**
     * 基金交易使用的货币种类
     */
    @Getter
    private String currency;

    /**
     * 投资顾问
     */
    @Getter
    private String advisorName;
    /**
     * 基金托管人
     */
    @Getter
    private String custodianName;
    /**
     * 基金经理描述
     */
    @Getter
    private String fundManager;
    /**
     * 投资策略
     */
    @Getter
    private String fundStrategyDescription;
    /**
     * 基金成立日期
     */
    @Getter
    private String inceptionDate;
    /**
     * 行业趋势
     */
    @Getter
    private String industryTrend;
    /**
     * 投资目标
     */
    @Getter
    private String investmentObjective;
    /**
     * 杠杆比例
     */
    @Getter
    private String leverage;
    /**
     * 杠杆比例描述
     */
    @Getter
    private String leverageNote;
    /**
     * 基金运作方式
     */
    @Getter
    private String operationType;
    /**
     * 备案编码
     */
    @Getter
    private String registerNumber;
    /**
     * 风险收益特征
     */
    @Getter
    private String riskReturnDesc;
    /**
     * 业绩比较基准
     */
    @Getter
    private String secondaryBenchmark;
    /**
     * 基金到期日期
     */
    @Getter
    private String dueDate;
    /**
     * 信息披露报告是否经托管机构复核
     */
    @Getter
    private String isReviewed;

    public String getFundCode() {
        return ReportParseUtils.matchFundCode(this.fundCode);
    }

    public String getFundName() {
        return this.fundName == null ? null : this.fundName.trim().replaceAll("- ", "");
    }

    public ReportFundInfoDTO() {
        super();
    }

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

    @Override
    public ReportFundInfoDO toEntity() {
        ReportFundInfoDO entity = new ReportFundInfoDO();
        entity.setFileId(this.getFileId());
        entity.setFundCode(this.getFundCode());
        entity.setCompanyName(this.companyName);
        entity.setCurrency(this.currency);
        entity.setFundName(this.getFundName());
        entity.setAdvisorName(this.advisorName);
        entity.setCustodianName(this.custodianName);
        entity.setFundManager(this.fundManager);
        entity.setFundStrategyDescription(this.fundStrategyDescription);
        entity.setInceptionDate(DateUtils.toDate(this.inceptionDate));
        entity.setIndustryTrend(this.industryTrend);
        entity.setInvestmentObjective(this.investmentObjective);
        entity.setLeverage(this.toBigDecimal(this.leverage));
        entity.setLeverageNote(this.leverageNote);
        entity.setOperationType(this.operationType);
        entity.setRegisterNumber(this.registerNumber);
        entity.setRiskReturnDesc(this.riskReturnDesc);
        entity.setSecondaryBenchmark(this.secondaryBenchmark);
        entity.setDueDate(DateUtils.toDate(this.dueDate));
        entity.setReviewed(Objects.equals("是", this.isReviewed) ? 1 : 0);
        this.initEntity(entity);
        return entity;
    }

    @Override
    public String toString() {
        return "{" +
                super.toString() +
                ", fundName='" + this.getFundName() + '\'' +
                ", fundCode='" + this.fundCode + '\'' +
                ", matchFundCode='" + this.getFundCode() + '\'' +
                ", companyName='" + this.companyName + '\'' +
                '}';
    }
}
