trigger:
  branches:
    include:
      - main
      - develop

pr:
  branches:
    include:
      - main
      - develop

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

stages:
  - stage: Build
    displayName: Build Stage
    jobs:
      - job: Build
        displayName: Build Job
        steps:
          - task: UseDotNet@2
            displayName: 'Install .NET SDK'
            inputs:
              packageType: 'sdk'
              version: '8.x'

          - script: dotnet restore
            displayName: 'Restore dependencies'

          - script: dotnet build --configuration $(buildConfiguration) --no-restore
            displayName: 'Build project'

          - script: dotnet test --configuration $(buildConfiguration) --no-build --logger "trx"
            displayName: 'Run tests'

          - task: PublishTestResults@2
            displayName: 'Publish test results'
            condition: succeededOrFailed()
            inputs:
              testResultsFiles: '**/*.trx'
              testRunTitle: 'Test Results'

          - script: dotnet publish --configuration $(buildConfiguration) --no-build --output $(Build.ArtifactStagingDirectory)
            displayName: 'Publish artifact'

          - task: PublishBuildArtifacts@1
            displayName: 'Publish build artifacts'
            inputs:
              PathtoPublish: '$(Build.ArtifactStagingDirectory)'
              ArtifactName: 'drop'
              publishLocation: 'Container'

  - stage: Deploy
    displayName: Deploy Stage
    dependsOn: Build
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
    jobs:
      - job: Deploy
        displayName: Deploy Job
        steps:
          - task: DownloadBuildArtifacts@1
            displayName: 'Download build artifacts'
            inputs:
              buildType: 'current'
              artifactName: 'drop'
              downloadPath: '$(System.ArtifactsDirectory)'

          - script: echo "Deploying artifacts from $(System.ArtifactsDirectory)/drop"
            displayName: 'Deploy step placeholder'
