resource "jenkins_folder" "delphi_qa_automation" {
  name   = "delphi-qa-automation"
  folder = data.jenkins_folder.delphi_monorepos.id
}

locals {
  delphi_qa_jobs = {
    row_level_security = {
      repository_name     = "delphi-qa-automation"
      job_name            = "row-level-security"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/row-level-security.groovy"
      schedule_expression = "H 5 * * 2   %ENVIRONMENT=dev;GRADLE_TARGET=ciDelphiRowLevelSecurityTests"

      disabled = false
    }

    api_endpoint = {
      repository_name     = "delphi-qa-automation"
      job_name            = "api-endpoint"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/api-endpoint.groovy"
      schedule_expression = "H 4 * * 1,3,5  %ENVIRONMENT=stage;GRADLE_TARGET=allSwaggerTests_JavaApi"

      disabled = false
    }

    api_endpoint_with_option = {
      repository_name     = "delphi-qa-automation"
      job_name            = "api-endpoint-with-option"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/api-endpoint-with-option.groovy"
      schedule_expression = "H 4 * * 1,3,5  %ENVIRONMENT=stage;GRADLE_TARGET=allSwaggerTests_JavaApi"

      disabled = false
    }

    artist_onboarding = {
      repository_name     = "delphi-qa-automation"
      job_name            = "artist-onboarding"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/artist-onboarding.groovy"
      schedule_expression = "H 4 * * 1,3,5  %ENVIRONMENT=stage;GRADLE_TARGET=allSwaggerTests_JavaApi"

      disabled = false
    }

    slz = {
      repository_name     = "delphi-qa-automation"
      job_name            = "slz"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/slz.groovy"
      schedule_expression = "H 5 * * 1,3,5   %ENVIRONMENT=dev;GRADLE_TARGET=ciDelphiSlzComponentTests"

      disabled = false
    }

    api_edge_tests = {
      repository_name     = "delphi-qa-automation"
      job_name            = "api-edge-tests"
      http_url            = "https://github.com/theorchard/delphi-qa-automation"
      ssh_url             = "git@github.com:theorchard/delphi-qa-automation.git"
      jenkinsfile_path    = "jenkins/api-edge-tests.groovy"
      schedule_expression = "H 4 * * 1,3,5  %ENVIRONMENT=stage;GRADLE_TARGET=ciDelphiJavaApiEdgeTests"

      disabled = false
    }
  }
}

module "delphi_qa_automation_schedule" {
  for_each = local.delphi_qa_jobs

  source = "../../modules/jenkins/scheduled-parametrized-pipeline"

  disabled = each.value["disabled"]

  folder = jenkins_folder.delphi_qa_automation.id

  jenkins_job_name          = lookup(each.value, "job_name", each.value["repository_name"])
  github_repository_name    = each.value["repository_name"]
  github_repository_ssh_url = each.value["ssh_url"]

  jenkinsfile_branch  = lookup(each.value, "jenkinsfile_branch", "master")
  jenkinsfile_path    = each.value["jenkinsfile_path"]
  schedule_expression = each.value["schedule_expression"]
}
