model {
    workflow edfbuilder_workflow "EDFbuilder" {
        step runEDP "Run edpbuilder script" {
            style {
                opacity 25%
            }
            step createCrossplaneNS "Create Crossplane namespace"
            step installCrossplaneHelm "Install Crossplane Helm Chart"
            step installCrossplaneFunctionsAndProviders "Install Crossplane Functions and Providers"
            step waitForCrossplaneFunctionsAndProviders "Wait for Crossplane Functions and Providers to become available"
            step setupCrossplaneServiceAccount "Apply cluster-admin role to crossplane shell provider service account"
            step createArgoCdNS "Create ArgoCD namespace"
            step createGiteaNS "Create Gitea namespace"
            step createArgoCdTlsCert "Create TLS Cert for Argo"
            step createGiteaTlsCert "Create TLS Cert for Forgejo"
            step createEDFBuilderDefinition "Create EDFbuilder crossplane definition (defines API)"
            step createEDFBuilderComposition "Create EDFbuilder crossplane composition (defines what happens when EDFbuilder is applied)"
        }

        step applyEDFBuilder "Applies EDFbuilder resource (and triggers creation)" {
            style {
                opacity 15%
            }
            
            step setEnvVars "Set required environment variables"
            step readWriteKubeConf "Make kube.conf write/readbale"
            step setWorkDir "Set workdir to /tmp/rundir"
            step cloneStacksRepo "Clone steps repo and checkout desired branch"
            step hydrateStacksWithValues "Hydrate Stacks with values"
            step createNamespaces "Create all required namespaces"
            step createGiteaAdminPass "Create Admin Password for Forgejo"
            step createGrafanaPass "Create Grafana Admin Password"
            step applyServiceMonitorCRD "Apply ServiceMonitor CRDs for Prometheus"
            step cloneIngressNginxChart "Git clone ingress-nginx helm chart"
            step isntallIngressNginx "Install ingress-nginx from cloned chart"
            step waitForIngress "Wait till ingress-nginx is ready"
            step cloneArgoCDHelm "Git clone ArgoCD Helm Chart"
            step installArgoCD "Install ArgoCD Helm Chart"
            step installArgoCDIngress "Install ingress for ArgoCD"
            step cloneForgejoHelmChart "Git clone Forgejo Helm Chart"
            step installForgejo "Install Forgejo Helm Chart"
            step installForgejoIngress "Install ingress for Forgejo"
            step waitForArgoCD "Wait till ArgoCD is available"
            step waitForForgejo "Wait till Forgejo is available"
            step createForgejoUser "Create technical user for Forgejo"
            step createForgejoRepo "Create repository for EDP state in Forgejo"
            step installForgejoRunner "Install Forgejo Runner deployment"
            step registerForgejoRunner "Create registration token secret for runner"
            step configGitIdentity "Configure Git identity"
            step configCrossplaneArgoCDProvider "Configure Crossplane ArgoCD provider"
            step configCrossplaneKindProvider "Configure Crossplane Kind provider"
            step uploadStacksToForgjo "Git push hydrated stacks to Forgejo isntance"
            step configArgoDockerRegistry "Configure Docker Registry for Argo Workflows"
            step createPackagesForgejoUser "Create packages user and token in Forgejo (unused?)"
            step installArgoCDStacks "Apply all selected ArgoCD stacks"
            step cleanup "Cleanup work folder and unset all env vars"

            setEnvVars -> readWriteKubeConf
            readWriteKubeConf -> setWorkDir
            setWorkDir -> cloneStacksRepo
            cloneStacksRepo -> hydrateStacksWithValues
            hydrateStacksWithValues -> createNamespaces
            createNamespaces -> createGiteaAdminPass
            createGiteaAdminPass -> createGrafanaPass
            createGrafanaPass -> applyServiceMonitorCRD
            applyServiceMonitorCRD -> cloneIngressNginxChart
            cloneIngressNginxChart -> isntallIngressNginx
            isntallIngressNginx -> waitForIngress
            waitForIngress -> cloneArgoCDHelm
            cloneArgoCDHelm -> installArgoCD
            installArgoCD -> installArgoCDIngress
            installArgoCDIngress -> cloneForgejoHelmChart
            cloneForgejoHelmChart -> installForgejo
            installForgejo -> installForgejoIngress
            installForgejoIngress -> waitForArgoCD
            waitForArgoCD -> waitForForgejo
            waitForForgejo -> createForgejoUser
            createForgejoUser -> createForgejoRepo
            createForgejoRepo -> installForgejoRunner
            installForgejoRunner -> registerForgejoRunner
            registerForgejoRunner -> configGitIdentity
            configGitIdentity -> configCrossplaneArgoCDProvider
            configCrossplaneArgoCDProvider -> configCrossplaneKindProvider
            configCrossplaneKindProvider -> uploadStacksToForgjo
            uploadStacksToForgjo -> configArgoDockerRegistry
            configArgoDockerRegistry -> createPackagesForgejoUser
            createPackagesForgejoUser -> installArgoCDStacks
            installArgoCDStacks -> cleanup
        }

        createCrossplaneNS -> installCrossplaneHelm
        installCrossplaneHelm -> installCrossplaneFunctionsAndProviders
        installCrossplaneFunctionsAndProviders -> waitForCrossplaneFunctionsAndProviders
        waitForCrossplaneFunctionsAndProviders -> setupCrossplaneServiceAccount
        setupCrossplaneServiceAccount -> createArgoCdNS
        createArgoCdNS -> createGiteaNS
        createGiteaNS -> createArgoCdTlsCert
        createArgoCdTlsCert -> createGiteaTlsCert
        createGiteaTlsCert -> createEDFBuilderDefinition
        createEDFBuilderDefinition -> createEDFBuilderComposition
        createEDFBuilderComposition -> applyEDFBuilder
    }
}
