package com.sckw.payment.model.dto;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Objects;

/**
 * @author xucaiqin
 * @date 2023-07-28 08:42:13
 */
public interface ISettlement {

    void setTrading(String trading);

    String getTrading();

    void setTradingLabel(String tradingLabel);

    void setStatus(Integer status);

    Integer getStatus();

    void setStatusLabel(String statusLabel);

    private DecimalFormat df() {
        return new DecimalFormat("0.00");
    }

    default String changePrice(BigDecimal price) {
        if (Objects.isNull(price)) {
            //金额为null时显示的金额
            return "";
        }
        return df().format(price);
    }

    default String changePercentage(BigDecimal pay, BigDecimal total) {
        if (Objects.isNull(pay)) {
            pay = new BigDecimal("0.0");
        }
        //分母为0的情况，直接返回百分比0.00%
        if (Objects.isNull(total)) {
            pay = new BigDecimal("0.0");
            total = new BigDecimal("1");
        }
        if (BigDecimal.ZERO.compareTo(total) == 0) {
            return "0.00%";
        }
        return df().format(pay.divide(total, 6, RoundingMode.HALF_UP).multiply(new BigDecimal("100.0"))) + "%";
    }
}
