package cn.iocoder.yudao.module.common.controller.admin.moldticketmanagement.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 计划类型枚举
 * 1-点检 2-保养
 */
@Getter
public enum MoldPlanTypeEnum {

    INSPECTION(1, "点检"),
    MAINTENANCE(2, "保养");

    private final Integer code;
    private final String description;

    MoldPlanTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据code获取枚举
     */
    public static MoldPlanTypeEnum getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (MoldPlanTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据code获取描述
     */
    public static String getDescriptionByCode(Integer code) {
        MoldPlanTypeEnum type = getByCode(code);
        return type != null ? type.getDescription() : "未知";
    }

    /**
     * 检查code是否有效
     */
    public static boolean isValidCode(Integer code) {
        return getByCode(code) != null;
    }

    /**
     * 获取所有code列表
     */
    public static List<Integer> getAllCodes() {
        return Arrays.stream(values())
                .map(MoldPlanTypeEnum::getCode)
                .collect(Collectors.toList());
    }

    /**
     * 获取所有描述列表
     */
    public static List<String> getAllDescriptions() {
        return Arrays.stream(values())
                .map(MoldPlanTypeEnum::getDescription)
                .collect(Collectors.toList());
    }

    /**
     * 获取code和描述的映射
     */
    public static Map<Integer, String> getCodeDescriptionMap() {
        Map<Integer, String> map = new LinkedHashMap<>();
        for (MoldPlanTypeEnum type : values()) {
            map.put(type.getCode(), type.getDescription());
        }
        return map;
    }
}