package com.izouma.nineth.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.izouma.nineth.annotations.Searchable;
import com.izouma.nineth.enums.OrderStatus;
import com.izouma.nineth.enums.PayMethod;
import com.izouma.nineth.enums.PayStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Entity
@Table(indexes={
        @Index(columnList="orderId"),
        @Index(columnList="giftOrderId"),
        @Index(columnList="orderNo", unique = true),

})
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("支付记录")
public class PaymentInfo extends BaseEntity{

    @ApiModelProperty("用户ID")
    private Long userId;

    @ApiModelProperty("订单ID")
    private Long orderId;

    @ApiModelProperty("转赠订单ID")
    private Long giftOrderId;

    @ApiModelProperty("订单编号")
    @Searchable
    private String orderNo;


    @ApiModelProperty("支付方式")
    @Enumerated(EnumType.STRING)
    private PayMethod payMethod;

    @ApiModelProperty("支付渠道")
    private String payChannel;

    @ApiModelProperty("状态")
    @Enumerated(EnumType.STRING)
    private PayStatus status;

    @ApiModelProperty("支付金额")
    @Column(precision = 10, scale = 2)
    private BigDecimal payAmt;

    @ApiModelProperty("商户名称")
    private String merchantName;

    @ApiModelProperty("商品标题")
    private String goodsTitle;

    @ApiModelProperty("支付失效时间")
    private String timeExpire;

    @JsonIgnore
    @ApiModelProperty("通知地址")
    @Column(length = 500)
    private String notifyUrl;

    @ApiModelProperty("通知时间")
    private LocalDateTime notifyTime;

    @ApiModelProperty("交易ID")
    @Searchable
    private String transactionId;

    @ApiModelProperty("支付方订单号")
    @Searchable
    private String thirdPayNo;

    @ApiModelProperty("支付平台")
    private String payPlatform;

    @ApiModelProperty("支付时间")
    private LocalDateTime payTime;

    /**
     * 记录退款流水
     */
    @ApiModelProperty("退款流水")
    private String refundNo;

    @ApiModelProperty("退款时间")
    private LocalDateTime refundTime;


    @ApiModelProperty("退款原因")
    private String refundReason;

    @ApiModelProperty("申请退款时间")
    private LocalDateTime applyRefundTime;

    @ApiModelProperty("项目ID")
    private Integer projectId;

    /**
     * 使用钱包账户支付
     */
    @ApiModelProperty("资金账户ID")
    private Long userFundAccountId;

    @ApiModelProperty("支付授权令牌")
    private String token;

    /**
     * user_bank_card的绑卡id
     */
    @ApiModelProperty("用户绑卡ID")
    private Long userBankCardId;

    /**
     * 查询订单状态
     */
    @Transient
    private OrderStatus orderStatus;


}
