# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

FLUTTER = File.join(ENV.fetch("FLUTTER_SDK", "C:/Users/daniel/fluttersdk/flutter"), "bin", "flutter")
FLUTTER_DIR = File.expand_path("../flutter", __dir__)

default_platform(:android)

platform :android do
  desc "Run Rust core-logic tests"
  lane :test_rust do
    Dir.chdir(File.expand_path("../core-logic", __dir__)) do
      sh("cargo test --features ffi --no-default-features")
    end
  end

  desc "Run Flutter analyze and tests"
  lane :test_flutter do
    Dir.chdir(FLUTTER_DIR) do
      sh(FLUTTER, "analyze", "--no-fatal-infos")
      sh(FLUTTER, "test")
    end
  end

  desc "Run all tests (Rust + Flutter)"
  lane :test do
    test_rust
    test_flutter
  end

  desc "Build release APK and AAB"
  lane :build do
    Dir.chdir(FLUTTER_DIR) do
      sh(FLUTTER, "build", "apk", "--release")
      sh(FLUTTER, "build", "appbundle", "--release")
    end
  end

  desc "Upload AAB to Google Play internal track"
  lane :deploy do
    supply(
      track: "internal",
      aab: File.join(FLUTTER_DIR, "build", "app", "outputs", "bundle", "release", "app-release.aab"),
      skip_upload_metadata: true,
      skip_upload_changelogs: false,
      skip_upload_images: true,
      skip_upload_screenshots: true,
    )
  end
end
