package com.red.circle.order.inner.model.dto;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 国家支持渠道详情
 * </p>
 *
 * @author pengliang
 * @since 2021-12-07
 */
@Data
@Accessors(chain = true)
public class SysPayCountryChannelDetailsDTO implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

  /**
   * 主键标识
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long id;

  /**
   * 开通支付国家id
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long payCountryId;

  /**
   * 国家渠道记录编号
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long countryChannelId;

  /**
   * 自家渠道code
   */
  private String channelCode;

  /**
   * 厂商code
   */
  private String factoryCode;

  /**
   * 第三方厂商code.
   */
  private String factoryChannel;

  /**
   * 厂商最小限制金额
   */
  private BigDecimal factoryMinLimit;

  /**
   * 最大支付金额
   */
  private BigDecimal factoryMaxLimit;

  /**
   * 厂商每日限额
   */
  private BigDecimal factoryDailyLimit;

  /**
   * 厂商最小限制金额-计算后
   */
  private BigDecimal computedMinLimit;

  /**
   * 最大支付金额-计算后
   */
  private BigDecimal computedMaxLimit;

  /**
   * 厂商每日限额-计算后
   */
  private BigDecimal computedDailyLimit;

  /**
   * 厂商货币小数点.
   */
  private Integer factoryCurrencyPoint;

  /**
   * 0.下架 1.上架
   */
  private Boolean shelf;


  public SysPayCountryChannelDetailsDTO computedLimit(BigDecimal rate) {
    this.computedMinLimit = multiply(this.factoryMinLimit, rate);
    this.computedMaxLimit = multiply(this.factoryMaxLimit, rate);
    this.computedDailyLimit = multiply(this.factoryDailyLimit, rate);
    return this;
  }

  private BigDecimal multiply(BigDecimal amount, BigDecimal rate) {
    return amount.multiply(rate).setScale(2, RoundingMode.UP);
  }
}
