parameters:
  # Optional: dependencies of the job
  dependsOn: ''

  # Optional: A defined YAML pool - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pool
  pool: ''
    
  CeapexPat: $(dn-bot-ceapex-package-r) # PAT for the loc AzDO instance https://dev.azure.com/ceapex
  GithubPat: $(BotAccount-dotnet-bot-repo-PAT)

  SourcesDirectory: $(Build.SourcesDirectory)
  CreatePr: true
  AutoCompletePr: false
  ReusePr: true
  UseLfLineEndings: true
  UseCheckedInLocProjectJson: false
  SkipLocProjectJsonGeneration: false
  LanguageSet: VS_Main_Languages
  LclSource: lclFilesInRepo
  LclPackageId: ''
  RepoType: gitHub
  GitHubOrg: dotnet
  MirrorRepo: ''
  MirrorBranch: main
  condition: ''
  JobNameSuffix: ''

jobs:
- job: OneLocBuild${{ parameters.JobNameSuffix }}
  
  dependsOn: ${{ parameters.dependsOn }}

  displayName: OneLocBuild${{ parameters.JobNameSuffix }}

  variables:
    - group: OneLocBuildVariables # Contains the CeapexPat and GithubPat
    - name: _GenerateLocProjectArguments
      value: -SourcesDirectory ${{ parameters.SourcesDirectory }}
        -LanguageSet "${{ parameters.LanguageSet }}"
        -CreateNeutralXlfs
    - ${{ if eq(parameters.UseCheckedInLocProjectJson, 'true') }}:
      - name: _GenerateLocProjectArguments
        value: ${{ variables._GenerateLocProjectArguments }} -UseCheckedInLocProjectJson
    - template: /eng/common/templates-official/variables/pool-providers.yml

  ${{ if ne(parameters.pool, '') }}:
    pool: ${{ parameters.pool }}
  ${{ if eq(parameters.pool, '') }}:
    pool:
      # We don't use the collection uri here because it might vary (.visualstudio.com vs. dev.azure.com)
      ${{ if eq(variables['System.TeamProject'], 'DevDiv') }}:
        name: AzurePipelines-EO
        image: 1ESPT-Windows2022
        demands: Cmd
        os: windows
      # If it's not devdiv, it's dnceng
      ${{ if ne(variables['System.TeamProject'], 'DevDiv') }}:
        name: $(DncEngInternalBuildPool)
        image: 1es-windows-2022
        os: windows

  steps:
    - ${{ if ne(parameters.SkipLocProjectJsonGeneration, 'true') }}:
      - task: Powershell@2
        inputs:
          filePath: $(Build.SourcesDirectory)/eng/common/generate-locproject.ps1
          arguments: $(_GenerateLocProjectArguments)
        displayName: Generate LocProject.json
        condition: ${{ parameters.condition }}

    - task: OneLocBuild@2
      displayName: OneLocBuild
      env:
        SYSTEM_ACCESSTOKEN: $(System.AccessToken)
      inputs:
        locProj: eng/Localize/LocProject.json
        outDir: $(Build.ArtifactStagingDirectory)
        lclSource: ${{ parameters.LclSource }}
        lclPackageId: ${{ parameters.LclPackageId }}
        isCreatePrSelected: ${{ parameters.CreatePr }}
        isAutoCompletePrSelected: ${{ parameters.AutoCompletePr }}
        ${{ if eq(parameters.CreatePr, true) }}:
          isUseLfLineEndingsSelected: ${{ parameters.UseLfLineEndings }}
          ${{ if eq(parameters.RepoType, 'gitHub') }}:
            isShouldReusePrSelected: ${{ parameters.ReusePr }}
        packageSourceAuth: patAuth
        patVariable: ${{ parameters.CeapexPat }}
        ${{ if eq(parameters.RepoType, 'gitHub') }}:
          repoType: ${{ parameters.RepoType }}
          gitHubPatVariable: "${{ parameters.GithubPat }}"
        ${{ if ne(parameters.MirrorRepo, '') }}:
          isMirrorRepoSelected: true
          gitHubOrganization: ${{ parameters.GitHubOrg }}
          mirrorRepo: ${{ parameters.MirrorRepo }}
          mirrorBranch: ${{ parameters.MirrorBranch }}
      condition: ${{ parameters.condition }}

    - task: 1ES.PublishBuildArtifacts@1
      displayName: Publish Localization Files
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/loc'
        PublishLocation: Container
        ArtifactName: Loc
      condition: ${{ parameters.condition }}

    - task: 1ES.PublishBuildArtifacts@1
      displayName: Publish LocProject.json
      inputs:
        PathtoPublish: '$(Build.SourcesDirectory)/eng/Localize/'
        PublishLocation: Container
        ArtifactName: Loc
      condition: ${{ parameters.condition }}