name: Build & Release Scale Gateway APK (DEPRECATED)
# ⚠️  This workflow is disabled. The Scale Gateway is deprecated since Kiosk v1.6.0.
# BLE scale support is now built into the EverShelf Kiosk app.
# Kept for reference — re-enable manually via workflow_dispatch if needed for legacy setups.

on:
  workflow_dispatch:
    inputs:
      confirm:
        description: "Type 'yes' to confirm you want to build the deprecated gateway APK"
        required: true

permissions:
  contents: write

jobs:
  build:
    name: Build APK
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

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

      - name: Set up Gradle
        uses: gradle/actions/setup-gradle@v3
        with:
          gradle-version: '8.4'

      - name: Build debug APK
        run: gradle assembleDebug --no-daemon
        working-directory: evershelf-scale-gateway

      - name: Rename APK
        run: |
          mkdir -p artifacts
          cp evershelf-scale-gateway/app/build/outputs/apk/debug/app-debug.apk artifacts/evershelf-scale-gateway.apk

      - name: Get version name
        id: version
        run: |
          VERSION=$(grep 'versionName' evershelf-scale-gateway/app/build.gradle.kts | grep -oP '"\K[^"]+')
          echo "name=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Delete existing latest release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: gh release delete latest --yes || true

      - name: Create GitHub Release and upload APK
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release create latest \
            --title "EverShelf Scale Gateway v${{ steps.version.outputs.name }}" \
            --notes "Download the APK and install it on your Android device (7.0+). Allow installation from unknown sources in settings." \
            --latest \
            artifacts/evershelf-scale-gateway.apk
