package com.inspect.metadata.mqtt.enums;

import lombok.Getter;

/**
 * 表示无人机系统中的各种控制与状态命令。
 */
@Getter
public enum HrTaskStepEnum {
    UNKNOWN(-1, "未知"), ALL(0, "全流程"), // 控制命令
    ONE_KEY_PREPARE(1, "一键准备"), ONE_KEY_LAUNCH(2, "一键放飞"), ONE_KEY_CLOSE(3, "一键关门"), ONE_KEY_LAND(4, "一键接机"), ONE_KEY_RECOVER(5, "一键回收"), ONE_KEY_POWER_OFF(6, "一键卸电"), ONE_KEY_POWER_TOGGLE(7, "一键开关机"), ONE_KEY_RESET(8, "一键复位"), WAIT(10, "等待"), ANTENNA_OUT(11, "天线伸出"), REMOTE_CONTROLLER_POWER_ON(12, "遥控器开机"), APP_START(13, "APP启动"), ANTENNA_RETRACT(14, "天线收回"),

    // 状态/任务命令
    DRONE_READY(101, "无人机就绪状态"), CONTROL_RIGHT_ACQUIRED(102, "控制权获取"), MISSION_DOWNLOAD(103, "航线下载"), MISSION_EXECUTE(104, "航线执行"), ONE_KEY_RETURN_HOME(105, "一键回家"), MEDIA_DOWNLOAD(106, "媒体文件下载"), EMERGENCY_LANDING(107, "备降点降落"), ONE_KEY_RELAND(108, "一键复降"), FOLLOW_LANDING(110, "跟随降落"), RETURN_TO_ALT_LAND(111, "返航备降悬停"), RESUME_FROM_BREAKPOINT(112, "断点续飞"),

    // 检查类命令
    RAIN_SNOW_CHECK(201, "雨雪检查"), WIND_SPEED_CHECK(202, "风速检查"), REMOTE_POWER_ON_CHECK(203, "遥控器上电"), TAKEOFF_CHECK(204, "起飞检查"), FLY_AWAY_30M_CHECK(205, "飞离30米检查"), RETURN_CHECK(206, "返航检查"), HOVER_CHECK(207, "悬停检查"), DISTANCE_CHECK(208, "距航站距离检查"), LANDING_CHECK(209, "降落检查"),

    PLATFORM_PRE_LAUNCH_CHECK(210, "平台放飞前检查"), LAUNCH_READY_CHECK(211, "放飞准备就绪检查"), PLATFORM_PRE_RECOVER_CHECK(212, "平台回收前检查"), RECOVER_READY_CHECK(213, "回收准备就绪检查"), RECOVER_COMPLETE_CHECK(214, "平台回收完成检查");

    private final Integer stepid;
    private final String description;

    HrTaskStepEnum(Integer stepid, String description) {
        this.stepid = stepid;
        this.description = description;
    }

    /**
     * 根据命令ID字符串获取对应的枚举实例
     *
     * @param stepid 命令ID，如 "01", "101" 等
     * @return 对应的枚举值，若未找到返回 null
     */
    public static HrTaskStepEnum fromstepid(Integer stepid) {
        for (HrTaskStepEnum command : values()) {
            if (command.stepid.equals(stepid)) {
                return command;
            }
        }
        return null;
    }

    /**
     * 判断某个 stepid 是否存在
     */
    public static boolean contains(Integer stepid) {
        return fromstepid(stepid) != null;
    }

    public static String getDescription(Integer stepid) {
        HrTaskStepEnum command = fromstepid(stepid);
        return command != null ? command.getDescription() + "异常，请检查" : "未知异常";
    }

    @Override
    public String toString() {
        return "HrTaskStepEnum{" + "stepid='" + stepid + '\'' + ", description='" + description + '\'' + '}';
    }
}
