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

public enum NutrimealOrderStatusEnum {

    UNPAID("待支付", 0),
    PAID("已支付", 1),
    ORDER_REC("已接单", 2),
    DELIVERING("配送中", 4),
    WAIT_FOR_PICKINGUP("待自取", 8),
    FINISHED("已完成", 16),
    CANCELED("已取消", 32),
    REFUND("已退款", 64)
    ;

    private String name;
    private int value;

    NutrimealOrderStatusEnum(String name, int value) {
        this.name = name;
        this.value = value;
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

//    public static String getDisplayName(int value) {
//        for (OrderStatusEnum orderStatusEnum : values()) {
//            if (orderStatusEnum.value == value) return orderStatusEnum.name;
//        }
//        return "";
//    }


    public static String getDisplayName(int value) {
        /** 方式一：
         for (MealOrderStatusEnum statusEnum : MealOrderStatusEnum.values()) {
         if ((statusEnum.value & value) == statusEnum.value && value < 2 * statusEnum.value) {
         return statusEnum.name;
         }
         }
         return "";
         */

        /**
         * 方式二：
         */
        if ((REFUND.value & value) == REFUND.value && (CANCELED.value & value) == CANCELED.value) {
            return REFUND.name;
        }
        if ((CANCELED.value & value) == CANCELED.value) {
            return CANCELED.name;
        }
        if ((FINISHED.value & value) == FINISHED.value) {
            return FINISHED.name;
        }
        if ((WAIT_FOR_PICKINGUP.value & value) == WAIT_FOR_PICKINGUP.value) {
            return WAIT_FOR_PICKINGUP.name;
        }
        if ((DELIVERING.value & value) == DELIVERING.value) {
            return DELIVERING.name;
        }
        if ((ORDER_REC.value & value) == ORDER_REC.value) {
            return ORDER_REC.name;
        }
        if ((PAID.value & value) == PAID.value) {
            return PAID.name;
        }
        if ((UNPAID.value & value) == UNPAID.value) {
            return UNPAID.name;
        }
        return "";
    }

    public static int getEnumValue(int value) {
        if ((REFUND.value & value) == REFUND.value && (CANCELED.value & value) == CANCELED.value) {
            return REFUND.value;
        }
        if ((CANCELED.value & value) == CANCELED.value) {
            return CANCELED.value;
        }
        if ((FINISHED.value & value) == FINISHED.value) {
            return FINISHED.value;
        }
        if ((WAIT_FOR_PICKINGUP.value & value) == WAIT_FOR_PICKINGUP.value) {
            return WAIT_FOR_PICKINGUP.value;
        }
        if ((DELIVERING.value & value) == DELIVERING.value) {
            return DELIVERING.value;
        }
        if ((ORDER_REC.value & value) == ORDER_REC.value) {
            return ORDER_REC.value;
        }
        if ((PAID.value & value) == PAID.value) {
            return PAID.value;
        }
        if ((UNPAID.value & value) == UNPAID.value) {
            return UNPAID.value;
        }
        return UNPAID.value;
    }
}
