package cn.pluss.platform.entity;

import cn.pluss.platform.api.SplitReq;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 商户分账配置表
 * </p>
 *
 * @author bzg
 * @since 2021-11-26
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("tb_pluss_merchant_split_setting")
@NoArgsConstructor
public class MerchantSplitSetting implements Serializable {

    private static final long serialVersionUID = 1L;

    public static String DEFAULT_IS_DIVISTION = "01";

    public static BigDecimal MAX_DIV_RATIO = BigDecimal.ONE;

    public static String DEFAULT_IS_CHARGEFEE = "02";

    public static String YES_IS_CHARGEFEE = "01";

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;


    /**
     * 主商户编号
     */
    @TableField("chieMerchantCode")
    private String chieMerchantCode;


    /**
     * 主商户id
     */
    @TableField("chieMerchantId")
    private String chieMerchantId;


    /**
     * 原订单是否参与分账01：是 02：否
     */
    @TableField("isDivistion")
    private String isDivistion;


    /**
     * 分账模式01：比例 02：金额
     */
    @TableField("divisionMode")
    private String divisionMode;


    /**
     * 分账商户号
     */
    @TableField("diviMerchantCode")
    private String diviMerchantCode;


    /**
     * 分账商户ID 对应channelStatus id
     */
    @TableField("diviMerchantId")
    private String diviMerchantId;


    /**
     * 分账金额
     */
    @TableField("divAmt")
    private BigDecimal divAmt;


    /**
     * 分账比例 最大4位小数 分账比例之和为1
     */
    @TableField("divRatio")
    private BigDecimal divRatio;


    /**
     * 是否收取手续费，若配置手续费收支分离，该参数配置的手续费承担方不生效
     */
    @TableField("isChargeFee")
    private String isChargeFee;


    /**
     * 创建时间
     */
    @TableField(value = "createTime", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 创建时间 开始时间
     */
    @TableField(exist = false, condition = "createTime &gt; #{%s}")
    private Date createTimeStart;

    /**
     * 创建时间 截止时间
     */
    @TableField(exist = false, condition = "createTime &lt; #{%s}")
    private Date createTimeEnd;

    /**
     * 状态 1：正常 0 关闭
     */
    @TableField("status")
    private Integer status;

    /**
     * 异步通知地址
     */
    @TableField("notifyUrl")
    private String notifyUrl;


    public MerchantSplitSetting(MerchantChannelStatus channel) {
        this.setChieMerchantCode(channel.getMerchantCode());
        this.setChieMerchantId(channel.getMerchantId());
        this.setDiviMerchantCode(channel.getMerchantCode());
        this.setDiviMerchantId(channel.getMerchantId());
        this.setDivisionMode(SplitReq.DivisionMode.SCALE.getValue());
        this.setDivRatio(MAX_DIV_RATIO);
        this.setIsChargeFee(DEFAULT_IS_CHARGEFEE);
        this.setIsDivistion(DEFAULT_IS_DIVISTION);
    }
}