package com.ywt.mg.domain.models.enums;


/**
 * 挂号订单状态
 */
public enum RegisteredStatusEnum {
    Pending("待支付", 0),
    Booked("已预约", 1),
    Cancel("已取消", 1 << 1),
    Took("已取号", 1 << 2),    //相当于 已支付
    Expired("已过期", 1 << 3),
    Back("已退号", 1 << 4),//相当于 已退款
    UNKNOWN("", 1 << 5);

    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 getRegisteredStatus(int value) {
        switch (value) {
            case 0:
                return Pending;
            case 1:
                return Booked;
            case 1 << 1:
                return Cancel;
            case 1 << 2:
                return Took;
            case 1<<3:
                return Expired;
            case 1 << 4:
                return Back;
            default:
                return UNKNOWN;
        }
    }

    // todo 此状态排序，只适用于后台订单显示
    public static int getValue(int status) {
        if (status == Pending.value){
            status = Pending.value;
        } else if ((status & Back.getValue()) > 0 && status < 2 * Back.getValue()) {
            status = Back.getValue();
        } else if ((status & Cancel.getValue()) > 0 && status < 2 * Cancel.getValue()) {
            status = Cancel.getValue();
        } else if ((status & Expired.getValue()) > 0 && status < 2 * Expired.getValue()) {
            status = Took.getValue();
        } else if ((status & Booked.getValue()) > 0 && status < 2 * Booked.getValue()) {
            status = Booked.getValue();
        } else if ((status & Took.getValue()) > 0 && status < 2 * Took.getValue()) {
            status = Took.getValue();
        }  else if ((status & UNKNOWN.getValue()) > 0 && status < 2 * UNKNOWN.getValue()) {
            status = UNKNOWN.getValue();
        }
        return status;
    }

}
