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.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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_info")
@NoArgsConstructor
public class RedPacketInfo extends BaseModel {

    private static final long serialVersionUID=1L;

    public static final byte NO_USE = 1;

    public static final byte IN_USE = 2;

    public static final byte YES_USE = 3;

    public static final byte EXPIRE = 4;

    public static final byte REFUND = 5;

    /**
     * 关联流水号
     */
    @TableId(type = IdType.INPUT)
    private String flowNo;

    /**
     * 付款用户ID
     */
    private String payUserId;

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

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

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

    /**
     * 交易金额
     */
    private Long transAmt;

    /**
     * 实付金额
     */
    private Long findAmt;

    /**
     * 红包折扣
     */
    private BigDecimal discountScale;

    /**
     * 红包奖励金额
     */
    private Long rewardAmt;

    /**
     * 实际差额
     */
    private Long actualAmt;

    /**
     * 已使用红包金额
     */
    private Long useAmt;

    /**
     * 交易时间
     */
    private Date transTime;

    /**
     * 来源 WECHAT：微信 ALIPAY：支付宝
     */
    private String type;

    /**
     * 红包有效期
     */
    private Date expireTime;

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

    /**
     * 状态1：未使用 2：使用中 3：已使用 4：已过期 5：已退款
     */
    private Byte state;

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

    /**
     * 备注
     */
    private String remark;

    public RedPacketInfo(RedPacketAccount packetAccount, RedPacketAccountOperate operate, Long findAmt, Long rewardAmt, BigDecimal marketScale, Date expireTime) {
        this.flowNo = operate.getFlowNo();
        this.payUserId = packetAccount.getPayUserId();
        this.mchNo = packetAccount.getMchNo();
        this.storeId = packetAccount.getStoreId();
        this.storeName = packetAccount.getStoreName();
        this.transAmt = operate.getOrderAmt();
        this.findAmt = findAmt;
        this.rewardAmt = rewardAmt;
        this.discountScale = marketScale;
        this.expireTime = expireTime;
        this.type = operate.getPayType();
        if(operate.getTransTime() == null){
            this.transTime = new Date();
        }else{
            this.transTime = operate.getTransTime();
        }
    }

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