package com.ywt.alipaympapi.models.enums;


/**
 * 挂号订单状态
 */
public enum RegisteredStatusEnum {
    //    Pending("待支付", 0),
    Paid("待支付", 1),
    Cancel("已取消", 1 << 1),
    Took("已取号", 1 << 2),    //相当于 已支付
    Refunded("已退款", 1 << 3),
    UNKNOWN("", 0);
//    Back("已退号", 1<< 4),//相当于 已退款
//    Settlement("已结算", 1 << 7);

    RegisteredStatusEnum(String displayName, int value) {
        this.displayName = displayName;
        this.value = value;
    }

    private final String displayName;

    private final int value;

    public String getDisplayName() {
        return displayName;
    }

    public int getValue() {
        return value;
    }


    public static RegisteredStatusEnum valueOf(int value) {
        // todo 如果有已退款，优先显示已退款
        if ((value & Refunded.getValue()) > 0) {
            return Refunded;
        }
        if ((value & Paid.getValue()) > 0 && value < 2 * Paid.value) {
            return Paid;
        } else if ((value & Cancel.getValue()) > 0 && value < 2 * Cancel.value) {
            return Cancel;
        } else if ((value & Took.getValue()) > 0 && value < 2 * Took.value) {
            return Took;
        } else if ((value & Refunded.getValue()) > 0 && value < 2 * Refunded.value) {
            return Refunded;
        }
        return UNKNOWN;
    }
}



