package com.czg.order.entity;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import java.io.Serial;

import jakarta.validation.constraints.NotBlank;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * 支付详情 实体类。
 *
 * @author ww
 * @since 2025-02-15
 */
@Data
@Table("tb_order_payment")
@Accessors(chain = true)
public class OrderPayment implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id(keyType = KeyType.Auto)
    private Long id;


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 店铺Id
     */
    private Long shopId;

    /**
     * 来源Id 订单Id或充值id
     */
    private Long sourceId;
    /**
     * 霸王餐充值为 订单id 会员充值为 活动id
     */
    private Long relatedId;

    /**
     * 支付方式：order,refund, memberIn,memberRefund, free
     */
    private String payType;

    /**
     * 支付单号  唯一 自己系统的 mchOrderNo
     */
    private String orderNo;

    /**
     * 微信或支付宝支付条码
     */
    private String authCode;

    /**
     * 金额
     */
    private BigDecimal amount;

    /**
     * 三方支付单号 返回结果的 payOrderId
     */
    private String tradeNumber;

    @Column(onUpdateValue = "now()")
    private LocalDateTime payTime;

    /**
     * 支付相应结果 json
     */
    private String respJson;
    /**
     * 支付状态：success, fail, init
     */
    private String payStatus;

    @Column(onInsertValue = "now()")
    private LocalDateTime createTime;

    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    private LocalDateTime updateTime;

    public OrderPayment() {
    }

    public OrderPayment(@NonNull Long shopId,@NonNull Long sourceId, @NotBlank String payType, @NotBlank String orderNo,
                        String authCode, @NonNull BigDecimal amount) {
        this.shopId = shopId;
        this.sourceId = sourceId;
        this.payType = payType;
        this.orderNo = orderNo;
        this.authCode = authCode;
        this.amount = amount;
        this.payStatus = "init";
    }

    public OrderPayment(@NonNull Long shopId,@NonNull Long sourceId, @NotBlank String payType, @NotBlank String orderNo,
                        String authCode, @NonNull BigDecimal amount, Long relatedId) {
        this.shopId = shopId;
        this.sourceId = sourceId;
        this.payType = payType;
        this.orderNo = orderNo;
        this.authCode = authCode;
        this.amount = amount;
        this.relatedId = relatedId;
        this.payStatus = "init";
    }
}
