package com.qqchen.deploy.backend.workflow.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 节点执行状态枚举
 * 所有工作流节点的统一执行状态
 *
 * @author qqchen
 * @since 2025-10-22
 */
@Getter
public enum NodeExecutionStatusEnum {

    /**
     * 执行成功
     */
    SUCCESS("SUCCESS", "执行成功"),

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

    @JsonValue
    private final String code;
    
    private final String description;

    NodeExecutionStatusEnum(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据编码获取枚举
     *
     * @param code 状态编码
     * @return 枚举实例
     */
    public static NodeExecutionStatusEnum fromCode(String code) {
        for (NodeExecutionStatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown NodeExecutionStatus code: " + code);
    }
}

