package com.qqchen.deploy.backend.deploy.dto.variables.build;

import com.qqchen.deploy.backend.workflow.annotation.CodeEditorConfig;
import com.qqchen.deploy.backend.workflow.annotation.SchemaProperty;
import com.qqchen.deploy.backend.workflow.annotation.SchemaPropertyDataSource;
import com.qqchen.deploy.backend.workflow.annotation.SchemaPropertyDataSourceParam;
import lombok.Data;

/**
 * Jenkins构建变量
 */
@Data
public class JenkinsBaseBuildVariables {

    @SchemaProperty(
        title = "绑定三方Jenkins系统",
        description = "请选择三方Jenkins系统",
        required = true,
        dataSource = @SchemaPropertyDataSource(
            type = "api",
            url = "/api/v1/external-system/list?type=JENKINS",
            valueField = "id",
            labelField = "name"
        ),
        order = 2
    )
    private String externalSystemId;


    @SchemaProperty(
        title = "绑定Jenkins视图",
        description = "Jenkins视图",
        required = true,
        dataSource = @SchemaPropertyDataSource(
            type = "api",
            url = "/api/v1/jenkins-view/list",
            valueField = "id",
            labelField = "viewName",
            dependsOn = {"externalSystemId"},
            params = {
                @SchemaPropertyDataSourceParam(name = "externalSystemId", value = "${externalSystemId}")
            }
        ),
        order = 3
    )
    private String viewId;


    @SchemaProperty(
        title = "绑定Jenkins任务",
        description = "Jenkins任务",
        required = true,
        dataSource = @SchemaPropertyDataSource(
            type = "api",
            url = "/api/v1/jenkins-job/list",
            valueField = "id",
            labelField = "jobName",
            dependsOn = {"externalSystemId", "viewId"},
            params = {
                @SchemaPropertyDataSourceParam(name = "externalSystemId", value = "${externalSystemId}"),
                @SchemaPropertyDataSourceParam(name = "viewId", value = "${viewId}")
            }
        ),
        order = 4
    )
    private String jobId;

    @SchemaProperty(
        title = "构建产物路径",
        description = "构建产物路径",
        order = 5
    )
    private String artifactPath;


    @SchemaProperty(
        title = "Pipeline script",
        description = "流水线脚本",
        required = true,
        format = "monaco-editor",  // 使用 Monaco Editor
        defaultValue = "#!/bin/bash\n\necho \"Hello World\"",
        codeEditor = @CodeEditorConfig(
            language = "shell",
            theme = "vs-dark",
            minimap = false,
            lineNumbers = true,
            wordWrap = true,
            fontSize = 14,
            tabSize = 2,
            autoComplete = true,
            folding = true
        ),
        order = 6
    )
    private String script;

}