package cn.iocoder.yudao.module.mes.controller.admin.repairtems.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 设备类型枚举
 */
@Getter
@AllArgsConstructor
@Schema(description = "设备类型枚举")
public enum DeviceTypeEnum {

    DEVICE(1, "设备"),
    CRITICAL_COMPONENT(2, "关键件");

    @Schema(description = "类型", example = "1")
    private final Integer type;

    @Schema(description = "描述", example = "设备")
    private final String description;

    /**
     * 根据类型获取枚举
     */
    public static DeviceTypeEnum getByType(Integer type) {
        if (type == null) {
            return null;
        }
        for (DeviceTypeEnum deviceType : DeviceTypeEnum.values()) {
            if (deviceType.getType().equals(type)) {
                return deviceType;
            }
        }
        return null;
    }

    /**
     * 根据类型获取描述
     */
    public static String getDescriptionByType(Integer type) {
        DeviceTypeEnum deviceType = getByType(type);
        return deviceType != null ? deviceType.getDescription() : "未知";
    }

    /**
     * 判断类型是否有效
     */
    public static boolean isValid(Integer type) {
        return getByType(type) != null;
    }

    /**
     * 获取所有类型列表
     */
    public static Map<Integer, String> getAllTypes() {
        Map<Integer, String> map = new LinkedHashMap<>();
        for (DeviceTypeEnum deviceType : values()) {
            map.put(deviceType.getType(), deviceType.getDescription());
        }
        return map;
    }
}