package com.red.circle.wallet.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 java.sql.Timestamp;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 用户货运账户.
 * </p>
 *
 * @author pengliang
 * @since 2021-07-07
 */
@Data
@Accessors(chain = true)
public class UserFreightBalanceDTO implements Serializable {

  @Serial
  private static final long serialVersionUID = 1L;

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

  /**
   * 归属平台.
   */
  private String sysOrigin;

  /**
   * 用户id.
   */
  @JsonSerialize(using = ToStringSerializer.class)
  private Long userId;

  /**
   * 获得糖果.
   */
  private BigDecimal earnPoints;

  /**
   * 消费糖果.
   */
  private BigDecimal consumptionPoints;

  /**
   * 创建时间.
   */
  private Timestamp createTime;

  /**
   * 修改时间.
   */
  private Timestamp updateTime;

  /**
   * 0.未关闭 1.已关闭.
   */
  private Boolean close;

  /**
   * 0.显示 1.不显示.
   */
  private Boolean display;

  /**
   * 是否经销商 0.否 1.是.
   */
  private Boolean dealer;

  /**
   * 是否超级经销商 0.否 1.是.
   */
  private Boolean superDealer;

  /**
   * 支持的国家（多个用逗号分隔）.
   */
  private String supportedCountries;

  /**
   * 联系方式.
   */
  private String contactInfo;

  /**
   * H5显示开关：0-不显示，1-显示.
   */
  private Boolean h5Display;

  /**
   * 授权卖家数量.
   */
  private Integer sellerQuantity;

  /**
   * 已授权卖家数量.
   */
  private Long realSellerQuantity;

  /**
   * 成为代理天数（根据createTime计算）.
   */
  private Integer becomeDays;

  /**
   * 交易数量（出货次数，type=1）.
   */
  private Long transactionCount;

  public BigDecimal getBalance() {
    return earnPoints.subtract(consumptionPoints).setScale(2, RoundingMode.DOWN);
  }
}
