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

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

/**
 * 构建方式枚举
 */
@Getter
public enum BuildTypeEnum {

    JENKINS(
        "JENKINS",
        "Jenkins构建",
        new DevelopmentLanguageTypeEnum[] {
            DevelopmentLanguageTypeEnum.JAVA,
            DevelopmentLanguageTypeEnum.NODE_JS,
            DevelopmentLanguageTypeEnum.GO,
            DevelopmentLanguageTypeEnum.PYTHON
        },
        "Jenkins构建"
    ),
    NATIVE(
        "NATIVE",
        "脚本部署",
        new DevelopmentLanguageTypeEnum[] {
            DevelopmentLanguageTypeEnum.JAVA
        },
        "通过自定义脚本进行构建部署"
    ),
    CODE_ARTS(
        "CODE_ARTS",
        "CodeArts构建",
        null,
        "CodeArts构建"
    ),
    GITLAB_RUNNER(
        "GITLAB_RUNNER",
        "GitLab Runner构建",
        null,
        "GitLab Runner构建"
    ),
    GITHUB_ACTION(
        "GITHUB_ACTION",
        "GitHub Action构建",
        null,
        "GitHub Action构建"
    );

    @JsonValue
    private final String code;

    private final String name;

    private final DevelopmentLanguageTypeEnum[] supportedLanguages;

    private final String description;

    BuildTypeEnum(String code, String name, DevelopmentLanguageTypeEnum[] supportedLanguages, String description) {
        this.code = code;
        this.name = name;
        this.supportedLanguages = supportedLanguages;
        this.description = description;
    }

    /**
     * 根据编码查找对应的枚举
     *
     * @param code 构建类型编码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 当找不到对应的枚举值时抛出
     */
    public static BuildTypeEnum fromValue(String code) {
        for (BuildTypeEnum type : values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown BuildType code: " + code);
    }
} 