package com.yonge.cooleshow.biz.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.yonge.cooleshow.common.enums.payment.EPaymentStatus;
import com.yonge.toolset.base.enums.BaseEnum;

/**
 * 订单状态 WAIT_PAY 待支付 PAYING 支付中  PAID 已付款 CLOSE 已关闭
 *
 * @Author: liweifan
 * @Data: 2022/3/31 14:59
 */
public enum OrderStatusEnum implements BaseEnum<String, OrderStatusEnum> {
    WAIT_PAY("待支付"),
    PAYING("支付中"),
    PAID("已付款"),
    CLOSE("已关闭"),
    FAIL("支付失败"),
    ;
    @EnumValue
    private String code;
    private String msg;

    OrderStatusEnum(String msg) {
        this.code = this.name();
        this.msg = msg;
    }


    //  EPaymentStatus to OrderStatusEnum
    public static OrderStatusEnum parse(EPaymentStatus paymentStatus) {
        if (paymentStatus == null) {
            return null;
        }
        switch (paymentStatus) {
            case WAIT_PAY:
                return WAIT_PAY;
            case PAYING:
                return PAYING;
            case PAID:
                return PAID;
            case TIMEOUT:
                return CLOSE;
            case FAIL:
                return FAIL;
            case CLOSED:
                return CLOSE;
            case REFUNDED:
                return PAID;
            default:
                return null;
        }
    }




    //  OrderStatusEnum 转 EPaymentStatus
    public static EPaymentStatus parse(OrderStatusEnum orderStatusEnum) {
        if (orderStatusEnum == null) {
            return null;
        }
        switch (orderStatusEnum) {
            case WAIT_PAY:
                return EPaymentStatus.WAIT_PAY;
            case PAYING:
                return EPaymentStatus.PAYING;
            case PAID:
                return EPaymentStatus.PAID;
            case CLOSE:
                return EPaymentStatus.CLOSED;
            case FAIL:
                return EPaymentStatus.FAIL;
            default:
                return null;
        }
    }

    public String getMsg() {
        return this.msg;
    }

    @Override
    public String getCode() {
        return this.code;
    }
}
