package com.izouma.nineth.dto.userfund;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 余额信息
 */
@Data
public class BalanceInfoDTO {

    private String bankAccount;

    private String accountType;

    private String accountStatus;

    /**
     * 可用余额
     */
    private BigDecimal availableBalance;

    /**
     * 冻结余额
     */
    private BigDecimal freezeBalance;

    /**
     * 待结算余额
     */
    private BigDecimal  psettleBalance;

    /**
     * 更新时间
     */
    private LocalDateTime freshTime = LocalDateTime.now();

    /**
     * 获取总金额
     * @return
     */
    @JsonProperty(access=JsonProperty.Access.READ_ONLY)
    public BigDecimal getTotalBalance(){
        BigDecimal totalBalance = BigDecimal.ZERO;
        if(availableBalance != null){
            totalBalance = totalBalance.add(availableBalance);
        }

        if(freezeBalance != null){
            totalBalance = totalBalance.add(freezeBalance);
        }

        if(psettleBalance != null){
            totalBalance = totalBalance.add(psettleBalance);
        }

        return totalBalance;
    }

}
