parameters:
  rootFolder: '$(Build.SourcesDirectory)'
  targetVersion: ''
  templateRoot: '$(Build.SourcesDirectory)'
  condition: true

steps:
  - pwsh: |
        ${{ parameters.templateRoot }}/eng/common/scripts/trust-proxy-certificate.ps1
    displayName: 'Language Specific Certificate Trust'
    condition: and(succeeded(), ${{ parameters.condition }})

  - task: PowerShell@2
    displayName: 'Override proxy version if necessary'
    condition: and(succeeded(), ${{ parameters.condition }}, ne('${{ parameters.targetVersion }}', ''))
    inputs:
      targetType: filePath
      filePath: '${{ parameters.templateRoot }}/eng/common/testproxy/override-proxy-version.ps1'
      arguments: '-TargetVersion "${{ parameters.targetVersion }}"'
      pwsh: true

  - pwsh: |
      docker info
    displayName: 'Dump active docker information'
    condition: and(succeeded(), ${{ parameters.condition }})

  - pwsh: |
      ${{ parameters.templateRoot }}/eng/common/testproxy/docker-start-proxy.ps1 -Mode start -TargetFolder "${{ parameters.rootFolder }}" -VersionOverride="${{ parameters.targetVersion }}"
    displayName: 'Run the docker container'
    condition: and(succeeded(), ${{ parameters.condition }})

  - pwsh: |
      docker container ls -a
    displayName: Check running container
    condition: and(succeeded(), ${{ parameters.condition }})

  - pwsh: |
      Write-Host "##vso[task.setvariable variable=PROXY_MANUAL_START]true"
    displayName: 'Set PROXY_MANUAL_START'
    condition: and(succeeded(), ${{ parameters.condition }})
