package com.ruoyi.credit.domain;

import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 统一银行数据模型
 * 整合银行管理界面和服务周期贷款系统的银行字段
 * 
 * @author ruoyi
 * @date 2025-12-25
 */
public class UnifiedBankData
{
    /** 银行ID */
    private Long bankId;
    
    /** 银行编码 */
    private String bankCode;
    
    /** 银行名称 */
    private String bankName;
    
    /** 银行类型 */
    private String bankType;
    
    /** 基准利率 */
    private Double baseInterestRate;
    
    /** 最低贷款金额 */
    private BigDecimal minLoanAmount;
    
    /** 最高贷款金额 */
    private BigDecimal maxLoanAmount;
    
    /** 最短期限（月） */
    private Integer minLoanTermMonths;
    
    /** 最长期限（月） */
    private Integer maxLoanTermMonths;
    
    /** 合作状态 */
    private String cooperationStatus;
    
    /** 银行状态 */
    private String status;
    
    /** 最后更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastUpdateTime;
    
    // 服务周期贷款系统特有字段
    /** 产品名称 */
    private String productName;
    
    /** 期限匹配度 */
    private String termMatch;
    
    /** 月还款额 */
    private BigDecimal monthlyPayment;
    
    /** 总利息 */
    private BigDecimal totalInterest;
    
    /** 实际利率（来自服务周期贷款系统） */
    private Double interestRate;
    
    /** 期限（月，来自服务周期贷款系统） */
    private Integer termMonths;
    
    /** 最大贷款金额（来自服务周期贷款系统） */
    private BigDecimal maxAmount;

    public UnifiedBankData() {
    }

    /**
     * 从BankInstitution转换为UnifiedBankData
     */
    public static UnifiedBankData fromBankInstitution(BankInstitution bankInstitution) {
        if (bankInstitution == null) {
            return null;
        }
        
        UnifiedBankData unified = new UnifiedBankData();
        unified.setBankId(bankInstitution.getBankId());
        unified.setBankCode(bankInstitution.getBankCode());
        unified.setBankName(bankInstitution.getBankName());
        unified.setBankType(bankInstitution.getBankType());
        unified.setBaseInterestRate(bankInstitution.getBaseInterestRate());
        unified.setMinLoanAmount(bankInstitution.getMinLoanAmountDecimal());
        unified.setMaxLoanAmount(bankInstitution.getMaxLoanAmountDecimal());
        unified.setMinLoanTermMonths(bankInstitution.getMinLoanTermMonths());
        unified.setMaxLoanTermMonths(bankInstitution.getMaxLoanTermMonths());
        unified.setCooperationStatus(bankInstitution.getCooperationStatus());
        unified.setStatus(bankInstitution.getStatus());
        unified.setLastUpdateTime(bankInstitution.getUpdateTime());
        
        return unified;
    }

    /**
     * 从服务周期贷款系统的Map数据转换为UnifiedBankData
     */
    public static UnifiedBankData fromServicePeriodLoanData(java.util.Map<String, Object> loanData) {
        if (loanData == null) {
            return null;
        }
        
        UnifiedBankData unified = new UnifiedBankData();
        unified.setBankId((Long) loanData.get("bankId"));
        unified.setBankName((String) loanData.get("bankName"));
        unified.setProductName((String) loanData.get("productName"));
        unified.setInterestRate((Double) loanData.get("interestRate"));
        unified.setTermMonths((Integer) loanData.get("termMonths"));
        unified.setMaxAmount((BigDecimal) loanData.get("maxAmount"));
        unified.setTermMatch((String) loanData.get("termMatch"));
        unified.setLastUpdateTime(new Date());
        
        return unified;
    }

    // Getters and Setters
    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public String getBankCode() {
        return bankCode;
    }

    public void setBankCode(String bankCode) {
        this.bankCode = bankCode;
    }

    public String getBankName() {
        return bankName;
    }

    public void setBankName(String bankName) {
        this.bankName = bankName;
    }

    public String getBankType() {
        return bankType;
    }

    public void setBankType(String bankType) {
        this.bankType = bankType;
    }

    public Double getBaseInterestRate() {
        return baseInterestRate;
    }

    public void setBaseInterestRate(Double baseInterestRate) {
        this.baseInterestRate = baseInterestRate;
    }

    public BigDecimal getMinLoanAmount() {
        return minLoanAmount;
    }

    public void setMinLoanAmount(BigDecimal minLoanAmount) {
        this.minLoanAmount = minLoanAmount;
    }

    public BigDecimal getMaxLoanAmount() {
        return maxLoanAmount;
    }

    public void setMaxLoanAmount(BigDecimal maxLoanAmount) {
        this.maxLoanAmount = maxLoanAmount;
    }

    public Integer getMinLoanTermMonths() {
        return minLoanTermMonths;
    }

    public void setMinLoanTermMonths(Integer minLoanTermMonths) {
        this.minLoanTermMonths = minLoanTermMonths;
    }

    public Integer getMaxLoanTermMonths() {
        return maxLoanTermMonths;
    }

    public void setMaxLoanTermMonths(Integer maxLoanTermMonths) {
        this.maxLoanTermMonths = maxLoanTermMonths;
    }

    public String getCooperationStatus() {
        return cooperationStatus;
    }

    public void setCooperationStatus(String cooperationStatus) {
        this.cooperationStatus = cooperationStatus;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getTermMatch() {
        return termMatch;
    }

    public void setTermMatch(String termMatch) {
        this.termMatch = termMatch;
    }

    public BigDecimal getMonthlyPayment() {
        return monthlyPayment;
    }

    public void setMonthlyPayment(BigDecimal monthlyPayment) {
        this.monthlyPayment = monthlyPayment;
    }

    public BigDecimal getTotalInterest() {
        return totalInterest;
    }

    public void setTotalInterest(BigDecimal totalInterest) {
        this.totalInterest = totalInterest;
    }

    public Double getInterestRate() {
        return interestRate;
    }

    public void setInterestRate(Double interestRate) {
        this.interestRate = interestRate;
    }

    public Integer getTermMonths() {
        return termMonths;
    }

    public void setTermMonths(Integer termMonths) {
        this.termMonths = termMonths;
    }

    public BigDecimal getMaxAmount() {
        return maxAmount;
    }

    public void setMaxAmount(BigDecimal maxAmount) {
        this.maxAmount = maxAmount;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
            .append("bankId", getBankId())
            .append("bankCode", getBankCode())
            .append("bankName", getBankName())
            .append("bankType", getBankType())
            .append("baseInterestRate", getBaseInterestRate())
            .append("minLoanAmount", getMinLoanAmount())
            .append("maxLoanAmount", getMaxLoanAmount())
            .append("minLoanTermMonths", getMinLoanTermMonths())
            .append("maxLoanTermMonths", getMaxLoanTermMonths())
            .append("cooperationStatus", getCooperationStatus())
            .append("status", getStatus())
            .append("lastUpdateTime", getLastUpdateTime())
            .append("productName", getProductName())
            .append("termMatch", getTermMatch())
            .append("monthlyPayment", getMonthlyPayment())
            .append("totalInterest", getTotalInterest())
            .append("interestRate", getInterestRate())
            .append("termMonths", getTermMonths())
            .append("maxAmount", getMaxAmount())
            .toString();
    }
}