package com.fs.enums;

/**
 * @author MixLiu
 * @date 2026/1/28 10:35
 * @description
 */
public enum ExecutionStatusEnum {
    /**
     * 成功
     */
    SUCCESS("SUCCESS", "执行成功", 1),

    /**
     * 失败
     */
    FAILURE("FAILURE", "执行失败", 2),

    /**
     * 进行中
     */
    RUNNING("RUNNING", "执行中", 3),

    /**
     * 暂停
     */
    PAUSED("PAUSED", "已暂停", 4),

    /**
     * 等待
     */
    WAITING("WAITING", "等待中", 5),

    /**
     * 取消
     */
    CANCELLED("CANCELLED", "已取消", 6),

    /**
     * 超时
     */
    TIMEOUT("TIMEOUT", "执行超时", 7),
    /**
     * 中断
     */
    INTERRUPT("INTERRUPT", "执行中断", 8),

    /**
     * 【初始化就绪】- 待执行
     */
    READY("READY", "初始化就绪", 9),

    /**
     * 待处理
     */
    PENDING("PENDING", "待处理", 10),

    /**
     * 等待人工外呼
     */
    WAITING_DO_CALL("WAITINGDOCALL", "等待人工外呼", 11);

    private final String code;
    private final String description;
    private final int value;

    ExecutionStatusEnum(String code, String description, int value) {
        this.code = code;
        this.description = description;
        this.value = value;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public int getValue() {
        return value;
    }

    /**
     * 根据状态码获取枚举值
     */
    public static ExecutionStatusEnum fromCode(String code) {
        for (ExecutionStatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown ExecutionStatus code: " + code);
    }

    /**
     * 根据int值获取枚举值
     */
    public static ExecutionStatusEnum fromValue(int value) {
        for (ExecutionStatusEnum status : values()) {
            if (status.value == value) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown ExecutionStatus value: " + value);
    }

    /**
     * 是否成功
     */
    public boolean isSuccess() {
        return this == SUCCESS;
    }

    /**
     * 是否失败
     */
    public boolean isFailure() {
        return this == FAILURE || this == TIMEOUT || this == CANCELLED;
    }
}
