package com.jeequan.jeepay.db.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jeequan.jeepay.core.entity.AccountOperate;
import com.jeequan.jeepay.core.model.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

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

/**
 * <p>
 * 账户变动明细
 * </p>
 *
 * @author [mybatis plus generator]
 * @since 2023-12-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "t_account_change_info")
@NoArgsConstructor
@AllArgsConstructor
public class AccountChangeInfo extends BaseModel {

    private static final long serialVersionUID=1L;

    public static final LambdaQueryWrapper<AccountChangeInfo> gw(AccountChangeInfo accountInfo){
        return new LambdaQueryWrapper<>(accountInfo);
    }

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

    /**
     * 流水号
     */
    @TableId(type = IdType.INPUT)
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY)
    private String flowNo;

    /**
     * 账户编号
     */
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY)
    private String accountNo;

    /**
     * 用户号
     */
    @TableField(whereStrategy = FieldStrategy.NOT_EMPTY)
    private String mchNo;

    /**
     * 账户类型 0：退款账户 1：营销账户 2：虚拟银行 3：钱包 4 手续费账户
     */
    @TableField(whereStrategy = FieldStrategy.NOT_NULL)
    private Byte accountType;

    /**
     * 变动类型 0：充值 1：提现 2：转账 3：退款 4：扣除
     */
    @TableField(whereStrategy = FieldStrategy.NOT_NULL)
    private Byte changeType;

    /**
     * 变动方式 0：扫码充值 1：对公转账 2：账户提现 3:平台户退款 -1:提现驳回 4：直付通
     */
    @TableField(whereStrategy = FieldStrategy.NOT_NULL)
    private Byte changeMethod;

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

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



    /**
     * 变动后的金额
     */
    private Long afterAmt;

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

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

    private String remark;


    public AccountChangeInfo(AccountOperate operate,AccountInfo account) {
        this.flowNo = operate.getOrderId();
        this.accountNo = operate.getAccountNo();
        this.mchNo = account.getInfoId();
        this.accountType = account.getType();
        this.changeType = operate.getChangeType();
        this.beforeAmt = account.getBalacne();
        this.changeAmt = operate.getChangeAmt();
        this.afterAmt = BigDecimal.valueOf(account.getBalacne()).add(BigDecimal.valueOf(operate.getChangeAmt())).longValue();
        this.remark = operate.getRemark();
        this.changeMethod = operate.getChangeMethod();
    }

}
