trigger:
  branches:
    include:
      - test
      - staging

resources:
  repositories:
    - repository: luk_vims
      type: git
      name: VANTEC-DEVOPS/LUK-VIMS-SHARED-PIPELINE-TEMPLATE
      ref: refs/heads/main

variables:
  project: "kuk"
  application: "vims-fullscreen"
  templateFile: "windows_vm_backup_and_deploy_template_config_folders_updated.yml"

parameters:
  - name: targetEnvironment
    displayName: "Target Environment"
    type: string
    default: auto
    values:
      - auto
      - test
      - staging
      - predeploy
      - main

  - name: environments
    type: object
    default:
      # 1. Deployment for branch: test
      - jobName: Test_Deployment
        repoBranch: "test"
        pollName: "VIMS-KUK"
        agentName: "VIMS-KUK-TEST-40"
        serverDriveLetter: "E:"
        phpPath: "E:/PHP"
        projectFolderName: "$(project)"
        environmentFilesFolderName: "test"
        performBackup: false

      # 2. Deployment for branch: staging
      - jobName: Staging_Deployment
        repoBranch: "staging"
        pollName: "VIMS-KUK"
        agentName: "LIMS-STAGING-13"
        serverDriveLetter: "F:"
        phpPath: "F:/PHP"
        projectFolderName: "$(project)-staging"
        environmentFilesFolderName: "staging"
        performBackup: true

      # 3. Deployment for branch: predeploy
      - jobName: Predeploy_Deployment
        repoBranch: "predeploy"
        pollName: "VIMS-KUK"
        agentName: "VIMS-KUK-LIVE-4"
        serverDriveLetter: "F:"
        phpPath: "F:/PHP"
        projectFolderName: "$(project)-predeploy"
        environmentFilesFolderName: "predeploy"
        performBackup: true

      # 4. Deployment for branch: main
      - jobName: Production_Deployment
        repoBranch: "main"
        pollName: "VIMS-KUK"
        agentName: "VIMS-KUK-LIVE-4"
        serverDriveLetter: "F:"
        phpPath: "F:/PHP"
        projectFolderName: "$(project)"
        environmentFilesFolderName: "production"
        performBackup: true

jobs:
  - ${{ each env in parameters.environments }}:
      - ${{ if or(eq(parameters.targetEnvironment, env.repoBranch), and(eq(parameters.targetEnvironment, 'auto'), eq(variables['Build.SourceBranch'], format('refs/heads/{0}', env.repoBranch)))) }}:
          - template: templates/${{ variables.application }}/${{ variables.project }}/${{ variables.templateFile }}@luk_vims
            parameters:
              jobName: ${{ env.jobName }}
              projectName: "$(project)"
              applicationName: "$(application)"
              repoBranch: ${{ env.repoBranch }}
              pollName: ${{ env.pollName }}
              agentName: ${{ env.agentName }}
              serverDriveLetter: ${{ env.serverDriveLetter }}
              phpPath: ${{ env.phpPath }}
              webrootFolderName: "WebRoot"
              projectFolderName: ${{ env.projectFolderName }}
              environmentFilesFolderName: ${{ env.environmentFilesFolderName }}
              performBackup: ${{ env.performBackup }}
              deployment_description: "KUK VIMS Full Screen - Branch ${{ env.repoBranch }}"
