package com.ai.trackwalker.demo;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

public enum DemoStep {
    INITIALIZING("run.initializing", "运行初始化", 3),
    TASK_CREATED("task.created", "巡检任务创建", 10),
    UAV_DISPATCHING("uav.dispatching", "航线任务下发", 18),
    RESOURCE_INGESTING("resource.ingesting", "多源数据接入", 28),
    PREPROCESS_RUNNING("preprocess.running", "数据预处理", 38),
    AI_INFERENCING("ai.inferencing", "AI推理分析", 55),
    RULE_EVALUATING("rule.evaluating", "GIS规则判定", 66),
    ALARM_GENERATING("alarm.generating", "告警生成", 76),
    WORKORDER_DISPATCHING("workorder.dispatching", "工单派发", 84),
    WORKORDER_CLOSING("workorder.closing", "工单闭环", 91),
    SAMPLE_FEEDBACK("sample.feedback", "样本回流", 96),
    RUN_COMPLETED("run.completed", "完成汇总", 100),
    RUN_CANCELLED("run.cancelled", "运行取消", 100),
    RUN_FAILED("run.failed", "运行失败", 100);

    private final String key;
    private final String label;
    private final int progress;

    DemoStep(String key, String label, int progress) {
        this.key = key;
        this.label = label;
        this.progress = progress;
    }

    public String key() {
        return key;
    }

    public String label() {
        return label;
    }

    public int progress() {
        return progress;
    }

    public static List<Map<String, Object>> timeline() {
        return Arrays.stream(values())
                .filter(step -> step != RUN_CANCELLED && step != RUN_FAILED)
                .map(step -> Map.<String, Object>of("key", step.key, "name", step.label, "progress", step.progress))
                .toList();
    }

    public static DemoStep fromKey(String key) {
        return Arrays.stream(values())
                .filter(step -> step.key.equals(key))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unknown demo step: " + key));
    }

    public static List<DemoStep> runnableSteps() {
        return Arrays.stream(values())
                .filter(step -> step != RUN_CANCELLED && step != RUN_FAILED)
                .toList();
    }
}
