package org.jebot.models.xxpay;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

@Data
@Entity(name = "t_pay_order")
@NoArgsConstructor
@AllArgsConstructor
public class PayOrder {

    @Id
    @Column(name = "PayOrderId")
    private String payOrderId;

    @Column(name = "MchId")
    private Long mchId;

    @Column(name = "MchType")
    private String mchType;

    @Column(name = "MchRate")
    private BigDecimal mchRate;

    @Column(name = "MchIncome")
    private BigDecimal mchIncome;

    @Column(name = "AppId")
    private String appId;

    @Column(name = "MchOrderNo")
    private String mchOrderNo;

    @Column(name = "AgentId")
    private String agentId;

    @Column(name = "ParentAgentId")
    private String parentAgentId;

    @Column(name = "AgentRate")
    private BigDecimal agentRate;

    @Column(name = "ParentAgentRate")
    private BigDecimal parentAgentRate;

    @Column(name = "AgentProfit")
    private BigDecimal agentProfit;

    @Column(name = "ParentAgentProfit")
    private BigDecimal parentAgentProfit;

    @Column(name = "ProductId")
    private Long productId;

    @Column(name = "PassageId")
    private Long passageId;

    @Column(name = "PassageAccountId")
    private String passageAccountId;

    @Column(name = "ChannelType")
    private String channelType;

    @Column(name = "ChannelId")
    private String channelId;

    @Column(name = "Amount")
    private BigDecimal amount;

    @Column(name = "Currency")
    private String currency;

    @Column(name = "Status")
    private Integer status;

    @Column(name = "ClientIp")
    private String clientIp;

    @Column(name = "Device")
    private String device;

    @Column(name = "Subject")
    private String subject;

    @Column(name = "Body")
    private String body;

    @Column(name = "Extra")
    private String extra;

    @Column(name = "ChannelUser")
    private String channelUser;

    @Column(name = "ChannelMchId")
    private String channelMchId;

    @Column(name = "ChannelOrderNo")
    private String channelOrderNo;

    @Column(name = "ChannelAttach")
    private String channelAttach;

    @Column(name = "PlatProfit")
    private BigDecimal platProfit;

    @Column(name = "ChannelRate")
    private BigDecimal channelRate;

    @Column(name = "ChannelCost")
    private BigDecimal channelCost;

    @Column(name = "PlatMchProfit")
    private BigDecimal platMchProfit;

    @Column(name = "PayPassageRate")
    private BigDecimal payPassageRate;

    @Column(name = "PayPassageCost")
    private BigDecimal payPassageCost;

    @Column(name = "IsRefund")
    private Boolean isRefund;

    @Column(name = "RefundTimes")
    private Integer refundTimes;

    @Column(name = "SuccessRefundAmount")
    private BigDecimal successRefundAmount;

    @Column(name = "ErrCode")
    private String errCode;

    @Column(name = "ErrMsg")
    private String errMsg;

    @Column(name = "Param1")
    private String param1;

    @Column(name = "Param2")
    private String param2;

    @Column(name = "NotifyUrl")
    private String notifyUrl;

    @Column(name = "ReturnUrl")
    private String returnUrl;

    @Column(name = "RandomRemark")
    private String randomRemark;

    @Column(name = "IsReissue")
    private Boolean isReissue;

    @Column(name = "ExpireTime")
    private Date expireTime;

    @Column(name = "PaySuccTime")
    private Date paySuccTime;

//    @Column(name = "PayOpenTime")
//    private Date payOpenTime;

    @Column(name = "CreateTime")
    private Date createTime;

    @Column(name = "UpdateTime")
    private Date updateTime;

    @Column(name = "ProductType")
    private String productType;

    @Column(name = "IsReConfirm")
    private Boolean isReConfirm;

    @Column(name = "IsDivision")
    private Boolean isDivision;

    @Column(name = "OrderAmount")
    private BigDecimal orderAmount;

    @Column(name = "PaymentAmount")
    private BigDecimal paymentAmount;

    @Column(name = "TopayUrl")
    private String topayUrl;

    @Column(name = "ChannelSMId")
    private String channelSMId;

    @Column(name = "SkName")
    private String skName;

    @Column(name = "SkBank")
    private String skBank;

    @Column(name = "SkCard")
    private String skCard;

    @Column(name = "BuyerId")
    private String buyerId;

    @Column(name = "FloatAmount")
    private BigDecimal floatAmount;

    @Column(name = "buyIdCount")
    private Integer buyIdCount;

    @Column(name = "buyIdCountAll")
    private Integer buyIdCountAll;

    //获取订单状态
    public String getStatusMsg() {
        switch (status) {
            case -2:
                return "订单已关闭";
            case 0:
                return "订单生成";
            case 1:
                return "支付中";
            case 2:
                return "支付成功";
            case 3:
                return "业务处理完成";
            case 4:
                return "已退款";
            default:
                return "未知状态";
        }
    }

    public PayOrder(BigDecimal amount, Long mchId, BigDecimal mchRate, Long passageId, Long productId, Integer status, Date createTime) {
        this.amount = amount;
        this.passageId = passageId;
        this.productId = productId;
        this.mchId = mchId;
        this.mchRate = mchRate;
        this.status = status;
        this.createTime = createTime;
    }

    public PayOrder(BigDecimal amount, Long mchId, BigDecimal mchRate, BigDecimal payPassageRate, Long passageId,  Integer status, Date createTime) {
        this.amount = amount;
        this.passageId = passageId;
        this.mchId = mchId;
        this.mchRate = mchRate;
        this.payPassageRate = payPassageRate;
        this.status = status;
        this.createTime = createTime;
    }


    public PayOrder(BigDecimal amount, Long mchId, BigDecimal mchRate, Long passageId, Integer status, Date createTime) {
        this.amount = amount;
        this.passageId = passageId;
        this.mchId = mchId;
        this.mchRate = mchRate;
        this.status = status;
        this.createTime = createTime;
    }
}