parameters:
  - name: TestName
    type: string
    default: 'LiveTest'
  - name: AdditionalPlatforms
    type: object
    default: {}
  - name: Clouds
    type: string
    default: 'Public'
  - name: SupportedClouds
    type: string
    default: 'Public'
  - name: UnsupportedClouds
    type: string
    default: ''
  - name: Artifacts
    type: object
    default: []
  - name: AdditionalModules
    type: object
    default: []
  - name: TestResultsFiles
    type: object
    default: ''
  - name: DisableAzureResourceCreation
    type: boolean
    default: false
  - name: PreSteps
    type: object
    default: []
  - name: PostSteps
    type: object
    default: []
  - name: EnvVars
    type: object
    default: {}
  - name: MaxParallel
    type: number
    default: 0
  - name: BuildInParallel
    type: boolean
    default: true
  - name: TimeoutInMinutes
    type: number
    default: 60
  - name: Location
    type: string
    default: ''
  - name: ServiceDirectory
    type: string
    default: not-specified
  - name: TestResourceDirectories
    type: object
    default:
  - name: TestSetupSteps
    type: stepList
    default: []
  - name: TestMode
    type: string
    default: 'LIVE'
  - name: TestVersionSupport
    type: boolean
    default: false
  - name: CloudConfig
    type: object
    default:
      Public:
        SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
      Preview:
        SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources-preview)
      Canary:
        SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
        Location: 'centraluseuap'
      UsGov:
        SubscriptionConfiguration: $(sub-config-gov-test-resources)
      China:
        SubscriptionConfiguration: $(sub-config-cn-test-resources)
  - name: MatrixConfigs
    type: object
    default:
      - Name: Java_live_test_base
        Path: eng/pipelines/templates/stages/native-platform-matrix.json
        Selection: sparse
        GenerateVMJobs: true
  - name: AdditionalMatrixConfigs
    type: object
    default: []
  - name: MatrixFilters
    type: object
    default: []
  - name: MatrixReplace
    type: object
    default: []
  - name: PlatformPreSteps
    type: object
    default: []
  - name: PlatformPostSteps
    type: object
    default: []
  - name: TestGoals
    type: string
    default: $(TestGoals)
  - name: TestOptions
    type: string
    default: $(TestOptions)
  - name: LtsVersion
    type: string
    default: $(JavaTestVersion)

stages:
  - ${{ each cloud in parameters.CloudConfig }}:
      - ${{ if or(contains(parameters.Clouds, cloud.key), and(contains(variables['Build.DefinitionName'], 'tests-weekly'), contains(parameters.SupportedClouds, cloud.key))) }}:
          - ${{ if not(contains(parameters.UnsupportedClouds, cloud.key)) }}:
              - stage: ${{ cloud.key }}_${{ parameters.TestName }}
                dependsOn: []
                jobs:
                  - template: /eng/common/pipelines/templates/jobs/archetype-sdk-tests-generate.yml
                    parameters:
                      SparseCheckoutPaths:
                        - "sdk/${{ parameters.ServiceDirectory }}/**/*.json"
                        - '!sdk/**/test-recordings/*'
                        - '!sdk/**/session-records/*'
                      JobTemplatePath: /eng/pipelines/templates/jobs/native.live.tests.yml
                      AdditionalParameters:
                        PreSteps:
                          - ${{ parameters.PlatformPreSteps }}
                          - ${{ parameters.PreSteps }}
                        PostSteps:
                          - ${{ parameters.PlatformPostSteps }}
                          - ${{ parameters.PostSteps }}
                        EnvVars: ${{ parameters.EnvVars }}
                        MaxParallel: ${{ parameters.MaxParallel }}
                        BuildInParallel: ${{ parameters.BuildInParallel }}
                        TimeoutInMinutes: ${{ parameters.TimeoutInMinutes }}
                        Location: ${{ parameters.Location }}
                        ServiceDirectory: ${{ parameters.ServiceDirectory }}
                        TestResourceDirectories: ${{ parameters.TestResourceDirectories }}
                        TestSetupSteps: ${{ parameters.TestSetupSteps }}
                        TestMode: ${{ parameters.TestMode }}
                        TestVersionSupport: ${{ parameters.TestVersionSupport }}
                        Artifacts: ${{ parameters.Artifacts }}
                        AdditionalModules: ${{ parameters.AdditionalModules }}
                        TestResultsFiles: ${{ parameters.TestResultsFiles }}
                        DisableAzureResourceCreation: ${{ parameters.DisableAzureResourceCreation }}
                        TestGoals: ${{ parameters.TestGoals }}
                        TestOptions: ${{ parameters.TestOptions }}

                      MatrixConfigs:
                        # Enumerate platforms and additional platforms based on supported clouds (sparse platform<-->cloud matrix).
                        - ${{ each config in parameters.MatrixConfigs }}:
                            -  ${{ config }}
                        - ${{ each config in parameters.AdditionalMatrixConfigs }}:
                            -  ${{ config }}
                      MatrixFilters:
                        - ${{ each cloudFilter in cloud.value.MatrixFilters }}:
                            - ${{ cloudFilter }}
                        - ${{ parameters.MatrixFilters }}
                      MatrixReplace:
                        - ${{ each cloudReplace in cloud.value.MatrixReplace }}:
                            - ${{ cloudReplace }}
                        - ${{ parameters.MatrixReplace }}
                      CloudConfig:
                        SubscriptionConfiguration: ${{ cloud.value.SubscriptionConfiguration }}
                        SubscriptionConfigurations: ${{ cloud.value.SubscriptionConfigurations }}
                        Location: ${{ coalesce(parameters.Location, cloud.value.Location) }}
                        Cloud: ${{ cloud.key }}
