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

import com.fasterxml.jackson.annotation.JsonValue;
import com.qqchen.deploy.backend.deploy.dto.variables.build.JenkinsJavaBuildVariables;
import com.qqchen.deploy.backend.deploy.dto.variables.build.JenkinsNodeJsBuildVariables;
import com.qqchen.deploy.backend.deploy.dto.variables.form.BuildFormVariables;
import lombok.Getter;

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

    JENKINS(
        "JENKINS",
        "Jenkins构建",
        new DevelopmentLanguageTypeEnum[] {
            DevelopmentLanguageTypeEnum.JAVA,
            DevelopmentLanguageTypeEnum.NODE_JS,
            DevelopmentLanguageTypeEnum.GO,
            DevelopmentLanguageTypeEnum.PYTHON
        },
        BuildFormVariables.class,
        new Class[] {
            JenkinsJavaBuildVariables.class,
            JenkinsNodeJsBuildVariables.class,
            null,
            null
        },
        "Jenkins构建"
    ),
    NATIVE(
        "NATIVE",
        "Native构建",
        null,
        null,
        null,
        "Native构建"
    ),
    CODE_ARTS(
        "CODE_ARTS",
        "CodeArts构建",
        null,
        null,
        null,
        "CodeArts构建"
    ),
    GITLAB_RUNNER(
        "GITLAB_RUNNER",
        "GitLab Runner构建",
        null,
        null,
        null,
        "GitLab Runner构建"
    ),
    GITHUB_ACTION(
        "GITHUB_ACTION",
        "GitHub Action构建",
        null,
        null,
        null,
        "GitHub Action构建"
    );

    @JsonValue
    private final String code;

    private final String name;

    private final DevelopmentLanguageTypeEnum[] supportedLanguages;

    private final Class<?> formVariablesSchema;

    private final Class<?>[] buildVariables;

    private final String description;

    BuildTypeEnum(String code, String name, DevelopmentLanguageTypeEnum[] supportedLanguages, Class<?> formVariablesSchema, Class<?>[] buildVariables, String description) {
        this.code = code;
        this.name = name;
        this.supportedLanguages = supportedLanguages;
        this.formVariablesSchema = formVariablesSchema;
        this.buildVariables = buildVariables;
        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);
    }
} 