# 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

# iOS
previous_build_number = latest_testflight_build_number(
  app_identifier: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
  api_key: app_store_connect_api_key,
)

current_build_number = previous_build_number + 1

increment_build_number(
  xcodeproj: "Runner.xcodeproj/project.pbxproj",
  build_number: current_build_number
)

# # android
# previous_build_number = google_play_track_version_codes(
#   package_name: app_id,
#   track: "internal",
#   json_key: json_key_file_path,
# )[0]

# current_build_number = previous_build_number + 1

# increment_version_code(
#   gradle_file_path: gradle_file_path,
#   version_code: current_build_number
# )

default_platform(:ios)

platform :ios do
  desc "Push a new beta build to TestFlight"
  lane :beta do
    build_app(workspace: "Runner.xcworkspace", scheme: "Runner")
    upload_to_testflight
  end
end

platform :ios do
  desc "Push a new build to app store"
  lane :store do
    build_app(workspace: "Runner.xcworkspace", scheme: "Runner")
    upload_to_app_store(force: true, precheck_include_in_app_purchases: false)
  end
end
