package com.yuchen.saas.payment.api.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yuchen.saas.payment.api.enums.OrderManageInvoiceStatusEnum;
import com.yuchen.saas.payment.api.enums.SaasInvoiceStatusEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.nest.springwrap.core.mp.base.BaseEntity;
import org.nest.springwrap.core.tenant.mp.TenantEntity;

import java.util.Date;

/**
 * <p>
 * 订单管理
 * </p>
 *
 * @author miaoqs
 * @since 2023-05-25
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("order_manage")
@ApiModel(value="OrderManage对象", description="订单管理")
public class OrderManage extends BaseEntity {

    /**
     * 订单来源编号：1.PC端，2.小程序端，3.公众号，4.APP
     */
    @ApiModelProperty(name = "orderSource", value = "订单来源编号：1.PC端，2.小程序端，3.公众号，4.APP")
    private String orderSource;

    /**
     * 应用id
     */
    @ApiModelProperty(name = "applyId", value = "应用id")
    private Long applyId;
    /**
     * 微信openId
     */
    @ApiModelProperty(name = "openId", value = "微信openId")
    private String openId;

    /**
     * 订单来源名称
     */
    @ApiModelProperty(name = "orderTitle", value = "订单来源名称")
    private String orderTitle;
    /**
     * 管理区ID
     */
    @ApiModelProperty(name = "manageArea", value = "管理区ID")
    private Long manageArea;

    /**
     * 场地id
     */
    @ApiModelProperty(name = "siteId", value = "场地ID")
    private Long siteId;
    /**
     * 管理区名称
     */
    @ApiModelProperty(name = "manageAreaName", value = "管理区名称")
    @TableField(exist = false)
    private String manageAreaName;
    /**
     * 订单号
     */
    @ApiModelProperty(name = "orderNo", value = "订单号")
    private String orderNo;
    /**
     * 订单分类
     */
    @ApiModelProperty(name = "orderClassify", value = "订单分类 XSDD:销售订单; FWDD:服务订单; JSDD:即时订单; TKDD:退款订单")
    private String orderClassify;
    /**
     * 订单类型 1or3 ：临停， 2月卡，20错时卡，26充电，30：占位费
     */
    @ApiModelProperty(name = "orderType", value = "订单类型 1or3 ：临停， 2月卡，20错时卡，26充电，30：占位费")
    private String orderType;
    /**
     * 应收金额(分)
     */
    @ApiModelProperty(name = "receivableAmount", value = "应收金额(分)")
    private Long receivableAmount;
    /**
     * 实收金额(分)
     */
    @ApiModelProperty(name = "actualAmount", value = "实收金额(分)")
    private Long actualAmount;
    /**
     * 优惠金额(分)
     */
    @ApiModelProperty(name = "discountsAmount", value = "优惠金额(分)")
    private Long discountsAmount;

    /**
     * 用户优惠券id
     */
    @ApiModelProperty(name = "couponCode", value = "用户优惠券id")
    private String couponCode;
    /**
     * 订单状态 0：待支付、1：支付中、2：支付成功、3：支付失败
     */
    @ApiModelProperty(name = "orderStats", value = "订单状态 -1：已关闭，0：待支付、1：支付中、2：支付成功、3：支付失败")
    private String orderStats;
    /**
     * 开票状态(0:开票中 1:开票成功 2:开票失败 3:红冲中(待退票) 4:已红冲(已退票) 5:被驳回 6:重开发票申请中 7:待作废 8:已作废 9:未开票 10:被驳回且重新申请 11:待红冲 12:红冲失败)
     */
    @ApiModelProperty(name = "invoicingStatus", value = "开票状态(0:开票中 1:开票成功 2:开票失败 3:红冲中(待退票) 4:已红冲(已退票) 5:被驳回 6:重开发票申请中 7:待作废 8:已作废 9:未开票 10:被驳回且重新申请 11:待红冲 12:红冲失败)")
    private Integer invoicingStatus;
    /**
     * 支付单id
     */
    @ApiModelProperty(name = "payId", value = "支付单id")
    private Long payId;
    /**
     * 支付单号
     */
    @ApiModelProperty(name = "payNo", value = "支付单号")
    private String payNo;

    /**
     * 业务账单单号
     */
    @ApiModelProperty(name = "billNo", value = "业务账单单号")
    private String billNo;
    /**
     * 支付时间
     */
    @ApiModelProperty(name = "payTime", value = "支付时间")
    private Date payTime;
    /**
     * 支付方式 1:微信支付; 2:钱包支付;
     */
    @ApiModelProperty(name = "payType", value = "支付方式 1:微信支付; 2:钱包支付;")
    private String payType;
    /**
     * 支付账号
     */
    @ApiModelProperty(name = "payAccount", value = "支付账号")
    private String payAccount;
    /**
     * 结算类型 1:自动结算; 2:用户结算;
     */
    @ApiModelProperty(name = "settleType", value = "结算类型 1:自动结算; 2:用户结算;3优惠卷直接抵扣;")
    private String settleType;
    /**
     * 流水对象ID
     */
    @ApiModelProperty(name = "streamObject", value = "流水对象ID")
    private Long streamObject;
    /**
     * 运营商ID
     */
    @ApiModelProperty(name = "operator", value = "运营商ID")
    private Long operator;


    /**
     * 平台用户id
     */
    @ApiModelProperty(name = "userDetailId", value = "平台用户id")
    private Long userDetailId;

    /**
     * 订单隐私保护
     */
    @ApiModelProperty(name = "privacyProtectionFlag", value = "订单隐私保护")
    private Integer privacyProtectionFlag;

    /**
     * 关闭状态（1：超时关闭，2：用户关闭，3：异常关闭）
     */
    @ApiModelProperty(name = "orderCloseStatus", value = "关闭状态（1：超时关闭，2：用户关闭，3：异常关闭）")
    private Integer orderCloseStatus;

    /**
     * 业务类型
     */
    @ApiModelProperty(name = "orderCloseStatus", value = "业务类型（1：智慧停车，2：智慧充电，3：智慧物业）")
    private Integer businessType;

    /**
     * 钱包id
     */
    @ApiModelProperty(name = "walletId", value = "钱包id")
    private Long walletId;

    /**
     * 钱包类型（1：平台钱包，2：渠道钱包）
     */
    @ApiModelProperty(name = "walletType", value = "钱包类型（1：平台钱包，2：渠道钱包）")
    private String walletType;

    /**
     * 支付渠道编码
     */
    @ApiModelProperty(name = "payChannelCode", value = "支付渠道编码（xc_pay：厦门银行，all_in_pay：通联支付）")
    private String payChannelCode;

    /**
     * 退款金额
     */
    @ApiModelProperty(name = "refundAmount", value = "退款金额")
    private Long refundAmount;
    /**
     * 关闭订单用户id
     */
    @ApiModelProperty(name = "orderCloseUserId", value = "关闭订单用户id")
    private Long orderCloseUserId;
    /**
     * 发票状态转换
     * @param invoicingStatus
     */
    public void setInvoicingStatusToSaasInvoiceStatus(Integer invoicingStatus) {
        if (SaasInvoiceStatusEnum.WAITING.getValue()==invoicingStatus){
            this.invoicingStatus = OrderManageInvoiceStatusEnum.WAITING.getValue();
        } else if (SaasInvoiceStatusEnum.SUCCESS.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.SUCCESS.getValue();
        }else if (SaasInvoiceStatusEnum.FAIL.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.NO.getValue();
        }else if (SaasInvoiceStatusEnum.TO_HONG_CHONG.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.SUCCESS.getValue();
        }else if (SaasInvoiceStatusEnum.HONG_CHONG_ZHONG.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.SUCCESS.getValue();
        }else if (SaasInvoiceStatusEnum.HONG_CHONG_LE.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.NO.getValue();
        }else if (SaasInvoiceStatusEnum.REJECTED.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.NO.getValue();
        }else if (SaasInvoiceStatusEnum.APPLY_INVOICE_AGAIN_WAITING.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.WAITING.getValue();
        }else if (SaasInvoiceStatusEnum.TOBECANCEL.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.SUCCESS.getValue();
        }else if (SaasInvoiceStatusEnum.CANCEL.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.NO.getValue();
        }else if (SaasInvoiceStatusEnum.REJECTED_AND_APPLY_AGAIN.getValue()==invoicingStatus) {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.WAITING.getValue();
        }else {
            this.invoicingStatus = OrderManageInvoiceStatusEnum.NO.getValue();
        }
    }

}
