name: GitHub Sponsor Simulation Check

# Builds both simulated states only inside the ephemeral GitHub-hosted runner.
# No APK is uploaded as an artifact or attached to a Release.
on:
  workflow_dispatch:
  pull_request:

permissions:
  contents: read

jobs:
  validate-simulation:
    name: Validate simulated ${{ matrix.state }} state
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        state:
          - locked
          - unlocked

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Java
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: "17"

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
          flutter-version: 3.27.4
          cache: true

      - name: Install dependencies
        run: flutter pub get --enforce-lockfile

      - name: Build simulated GitHub Sponsor state
        run: |
          flutter build apk --debug \
            --dart-define=LINTHRA_DISTRIBUTION=github \
            --dart-define=LINTHRA_GITHUB_SPONSOR_SIMULATION=${{ matrix.state }}

      - name: Verify APK and remove it
        run: |
          set -euo pipefail
          apk="build/app/outputs/flutter-apk/app-debug.apk"
          if [ ! -f "$apk" ]; then
            echo "::error::Expected debug APK not found at $apk."
            exit 1
          fi
          rm -f "$apk"
          test ! -f "$apk"
