// TaskTypeEnum.java
package cn.iocoder.yudao.module.iot.controller.admin.device.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum TaskTypeEnum {

    DEVICE("DEVICE", "设备数据采集"),
    WORK_ORDER("WORK_ORDER", "工单生成");

    /**
     * 任务类型编码
     */
    private final String code;

    /**
     * 任务类型名称
     */
    private final String name;

    /**
     * 根据编码获取枚举
     */
    public static TaskTypeEnum getByCode(String code) {
        for (TaskTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 检查编码是否存在
     */
    public static boolean contains(String code) {
        return getByCode(code) != null;
    }

    /**
     * 生成任务ID
     */
    public Long generateTaskId(Long baseId) {
        if (baseId == null) {
            baseId = 0L;
        }

        switch (this) {
            case DEVICE:
                return 1000000L + baseId;
            case WORK_ORDER:
                return 2000000L + baseId;
            default:
                return 9000000L + baseId;
        }
    }
}