package cn.pluss.platform.entity;

import cn.pluss.platform.enums.BstLevelCode;
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.time.LocalDate;
import java.util.Date;

/**
 * <p>
 * 直营贝斯特管理奖流水表
 * </p>
 *
 * @author bzg
 * @since 2022-01-23
 */
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@Accessors(chain = true)
@TableName("tb_pluss_user_reward_flow")
public class UserRewardFlow implements Serializable {

    private static final long serialVersionUID = 1L;


    public static final int TYPE_DIRE = 1;

    public static final int TYPE_INRE = 2;
    /**
     * ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;


    /**
     * 用户Id
     */
    @TableField("userId")
    private Long userId;


    /**
     * 父级ID
     */
    @TableField("parentId")
    private Long parentId;


    /**
     * T2流水
     */
    @TableField("t2Flow")
    private BigDecimal t2Flow;


    /**
     * T3流水
     */
    @TableField("t3Flow")
    private BigDecimal t3Flow;


    /**
     * 分红流水
     */
    @TableField("dividFlow")
    private BigDecimal dividFlow;


    /**
     * 区域流水
     */
    @TableField("areaFlow")
    private BigDecimal areaFlow;


    @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;

    @TableField("createDate")
    private LocalDate createDate;


    /**
     * 订单号
     */
    @TableField("orderNumber")
    private String orderNumber;

    /**
     * 状态1：已支付，2：已退款
     */
    @TableField("status")
    private Integer status;



    public UserRewardFlow(UserApp userApp, MerchantOrder order,int type) {
        this.userId = userApp.getUserId();
        this.parentId = userApp.getParentId();
        if(type == TYPE_DIRE){
            this.t2Flow = BigDecimal.valueOf(order.getConsumeFee());
        }
        if(type == TYPE_INRE){
            this.t3Flow = BigDecimal.valueOf(order.getConsumeFee());
        }
        this.dividFlow = BigDecimal.ZERO;
        this.areaFlow = BigDecimal.ZERO;
        this.orderNumber = order.getOrderNumber();
    }
}