# Fastlane lanes for Tod@s contra el Fuego (org.comunes.fires).
#
# Publishing is automated and password-free: a git tag triggers CI, which builds
# a signed AAB and runs `deploy_play`. Credentials come from CI secrets, never
# typed by hand:
#   SUPPLY_JSON_KEY_DATA  Google Play service-account JSON (raw contents)
#
# The store listing (titles, descriptions, changelogs, screenshots) is read
# straight from fastlane/metadata/android/<locale>/.

default_platform(:android)

# Release bundle produced by `flutter build appbundle --release --flavor
# production`, relative to the project root (where fastlane runs).
AAB_PATH = "build/app/outputs/bundle/productionRelease/app-production-release.aab".freeze

platform :android do
  desc "Upload the signed AAB + store listing to Google Play (internal track)"
  lane :deploy_play do
    supply(
      track: "internal",
      aab: AAB_PATH,
      release_status: "completed", # internal testing has no review delay
      skip_upload_apk: true,       # we ship the AAB, not a raw APK
      skip_upload_changelogs: false,
    )
  end

  desc "Push only the store listing (text + images), no binary"
  lane :deploy_metadata do
    supply(
      skip_upload_aab: true,
      skip_upload_apk: true,
    )
  end

  # Promote the release currently on the internal track to production, reusing
  # the SAME already-reviewed AAB (no rebuild, no new versionCode). Requires the
  # service account to have "Release to production" permission in Play Console.
  # Usage:  bundle exec fastlane promote_production
  desc "Promote the internal-track release to production (no rebuild)"
  lane :promote_production do
    supply(
      track: "internal",
      track_promote_to: "production",
      skip_upload_aab: true,
      skip_upload_apk: true,
      skip_upload_metadata: true,
      skip_upload_changelogs: true,
      skip_upload_images: true,
      skip_upload_screenshots: true,
    )
  end
end
