package com.yupi.project.model.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * 机器人任务的状态枚举
 */
@Getter
public enum RobotTaskStatusEnum {
    PENDING("PENDING", "待处理"),
    SENT("SENT", "已发送"),
    PROCESSING("PROCESSING", "处理中"),
    COMPLETED("COMPLETED", "已完成"),
    FAILED("FAILED", "已失败"),
    TIMED_OUT("TIMED_OUT", "已超时");

    private final String value;
    private final String description;

    RobotTaskStatusEnum(String value, String description) {
        this.value = value;
        this.description = description;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static RobotTaskStatusEnum fromValue(String value) {
        return Arrays.stream(values())
                .filter(enumInstance -> enumInstance.value.equalsIgnoreCase(value))
                .findFirst()
                .orElse(null);
    }

    /**
     * 判断是否为最终状态 (COMPLETED, FAILED, TIMED_OUT)
     * @param status 要检查的状态
     * @return 如果是最终状态则为 true
     */
    public static boolean isFinalStatus(RobotTaskStatusEnum status) {
        if (status == null) return false;
        return status == COMPLETED || status == FAILED || status == TIMED_OUT;
    }

    /**
     * 判断当前枚举实例是否为最终状态
     * @return 如果是最终状态则为 true
     */
    public boolean isFinalStatus() {
        return this == COMPLETED || this == FAILED || this == TIMED_OUT;
    }
} 