package com.jeequan.jeepay.db.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeequan.jeepay.core.model.BaseModel;
import com.jeequan.jeepay.model.RedPacketAccountOperate;
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 [mybatis plus generator]
 * @since 2024-01-18
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_red_packet_account_detail")
@NoArgsConstructor
public class RedPacketAccountDetail extends BaseModel {

    private static final long serialVersionUID=1L;

    public final static byte PAYMENT = 1;

    public final static byte REFUND = 2;

    public final static byte DEDUCT = 3;

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 用户号
     */
    private String mchNo;

    /**
     * 关联流水号
     */
    private String flowNo;

    /**
     * 门店id
     */
    private String storeId;

    /**
     * 门店名称
     */
    private String storeName;

    /**
     * 所属付款用户id
     */
    private String payUserId;

    /**
     * 类型：1：下单奖励 2：消费退款 3：红包抵扣
     */
    private Byte type;

    /**
     * 变动前余额
     */
    private Long beforeAmt;

    /**
     * 变动金额
     */
    private Long changeAmt;

    /**
     * 变动后余额
     */
    private Long afterAmt;

    /**
     * 创建时间
     */
    private Date createdAt;

    /**
     * 更新时间
     */
    private Date updatedAt;

    public RedPacketAccountDetail(RedPacketAccount packetAccount, RedPacketAccountOperate operate,Long beforeAmt,Long changeAmt) {
        this.mchNo = packetAccount.getMchNo();
        this.payUserId = packetAccount.getPayUserId();
        this.storeId = packetAccount.getStoreId();
        this.storeName = packetAccount.getStoreName();
        this.flowNo = operate.getFlowNo();
        this.beforeAmt = beforeAmt;
        this.changeAmt = changeAmt;
        this.afterAmt = BigDecimal.valueOf(beforeAmt).add(BigDecimal.valueOf(changeAmt)).longValue();
        this.type = operate.getType();
    }


    public static LambdaQueryWrapper<RedPacketAccountDetail> gw(RedPacketAccountDetail info) {
        return new LambdaQueryWrapper<>(info);
    }
}
