name: "Acceptance stage"

on:
  workflow_call:
    inputs:
      build_datetime:
        description: "Build datetime, set by the CI/CD pipeline workflow"
        required: true
        type: string
      build_timestamp:
        description: "Build timestamp, set by the CI/CD pipeline workflow"
        required: true
        type: string
      build_epoch:
        description: "Build epoch, set by the CI/CD pipeline workflow"
        required: true
        type: string
      nodejs_version:
        description: "Node.js version, set by the CI/CD pipeline workflow"
        required: true
        type: string
      python_version:
        description: "Python version, set by the CI/CD pipeline workflow"
        required: true
        type: string
      terraform_version:
        description: "Terraform version, set by the CI/CD pipeline workflow"
        required: true
        type: string
      version:
        description: "Version of the software, set by the CI/CD pipeline workflow"
        required: true
        type: string

jobs:
  environment-set-up:
    name: "Environment set up"
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Create infractructure"
        run: |
          echo "Creating infractructure..."
      - name: "Update database"
        run: |
          echo "Updating database..."
      - name: "Deploy application"
        run: |
          echo "Deploying application..."
  test-contract:
    name: "Contract test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run contract test"
        run: |
          make test-contract
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-security:
    name: "Security test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run security test"
        run: |
          make test-security
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-ui:
    name: "UI test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run UI test"
        run: |
          make test-ui
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-ui-performance:
    name: "UI performance test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run UI performance test"
        run: |
          make test-ui-performance
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-integration:
    name: "Integration test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run integration test"
        run: |
          make test-integration
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-accessibility:
    name: "Accessibility test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run accessibility test"
        run: |
          make test-accessibility
      - name: "Save result"
        run: |
          echo "Nothing to save"
  test-load:
    name: "Load test"
    runs-on: ubuntu-latest
    needs: environment-set-up
    timeout-minutes: 10
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Run load tests"
        run: |
          make test-load
      - name: "Save result"
        run: |
          echo "Nothing to save"
  environment-tear-down:
    name: "Environment tear down"
    runs-on: ubuntu-latest
    needs:
      [
        test-accessibility,
        test-contract,
        test-integration,
        test-load,
        test-security,
        test-ui-performance,
        test-ui,
      ]
    if: always()
    timeout-minutes: 5
    steps:
      - name: "Checkout code"
        uses: actions/checkout@v4
      - name: "Tear down environment"
        run: |
          echo "Tearing down environment..."
