package com.ruoyi.ss.order.domain.enums;

import com.ruoyi.common.exception.ServiceException;
import static com.ruoyi.common.constant.ServiceConstants.*;

/**
 * 订单类型枚举
 * @author qzz
 * 2025/1/9
 */
public enum OrderType {
    TEA(ORDER_TYPE_TEA, ORDER_TYPE_TEA_PREFIX, ORDER_TYPE_TEA_REORDER_PREFIX),
    MAHJONG(ORDER_TYPE_MAHJONG, ORDER_TYPE_MAHJONG_PREFIX, ORDER_TYPE_MAHJONG_REORDER_PREFIX),
    BILLIARDS(ORDER_TYPE_BILLIARDS, ORDER_TYPE_BILLIARDS_PREFIX, ORDER_TYPE_BILLIARDS_REORDER_PREFIX),
    CONTAINER(ORDER_TYPE_CONTAINER, ORDER_TYPE_CONTAINER_PREFIX, ORDER_TYPE_CONTAINER_PREFIX);

    private final String type;
    private final String prefix;
    private final String reorderPrefix;

    OrderType(String type, String prefix, String reorderPrefix) {
        this.type = type;
        this.prefix = prefix;
        this.reorderPrefix = reorderPrefix;
    }

    public String getPrefix(boolean isReorder) {
        return isReorder ? reorderPrefix : prefix;
    }

    public static OrderType fromType(String type) {
        for (OrderType orderType : values()) {
            if (orderType.type.equals(type)) {
                return orderType;
            }
        }
        throw new ServiceException("非法的订单类型");
    }
}
