# 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

default_platform(:android)

platform :android do
  def with_retries(times: 3, sleep_time: 10)
    tries = 0
    begin
      yield
    rescue => e
      tries += 1
      if tries < times
        UI.error("Retrying due to error: #{e}")
        sleep(sleep_time)
        retry
      else
        raise
      end
    end
  end

  desc "Upload App to Play Store Internal"
  lane :beta do
    upload_to_play_store(
      package_name: 'chat.rocket.android',
      track: 'internal',
      aab: 'app/build/outputs/bundle/release/app-release.aab'
    )
  end

  desc "Upload App to Internal App Sharing"
  lane :internal_app_sharing do
    upload_to_play_store_internal_app_sharing(
      package_name: 'chat.rocket.android',
      aab: 'app/build/outputs/bundle/release/app-release.aab'
    )
  end

  desc "Upload App to Play Store Open Testing"
  lane :open_testing do
    upload_to_play_store(
      package_name: 'chat.rocket.android',
      track: 'beta',
      aab: 'app/build/outputs/bundle/release/app-release.aab',
      skip_upload_metadata: true,
      skip_upload_changelogs: false,
      skip_upload_images: true,
      skip_upload_screenshots: true
    )
  end
end
