# 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
  desc "Runs all the tests"
  lane :test do
    gradle(task: "app:cAT")
  end

  desc "Submit a new Beta Build to Pgyer"
  lane :beta do
    gradle(task: "clean app:assembleRelease")
    # https://www.pgyer.com/doc/view/fastlane
    pgyer(
      api_key: ENV["PGYER_API_KEY"],
      update_description: File.read(Dir["./metadata/android/zh-CN/changelogs/*.txt"][-1])
    )
  end

  desc "Deploy a new version to the Google Play"
  lane :deploy do |options|
    # https://docs.fastlane.tools/actions/upload_to_play_store/
    # skip_upload_aab           Whether to skip uploading AAB	                                false
    # skip_upload_metadata      Whether to skip uploading metadata, changelogs not included	    false
    # skip_upload_images        Whether to skip uploading images, screenshots not included	    false
    # skip_upload_screenshots   Whether to skip uploading SCREENSHOTS	                        false
    # skip_upload_changelogs    Whether to skip uploading changelogs	                        false
    case options[:mode]
    when "metadata"
        # Upload metadata and images, screenshots not included
        upload_to_play_store(
            skip_upload_aab: true,
            skip_upload_screenshots: true,
            skip_upload_changelogs: true
        )
    when "screenshots"
        # Device art generator
        #   https://developer.android.google.cn/distribute/marketing-tools/device-art-generator
        # Screenshot Devices:
        #   phone:      Pixel 6                     1080x2400
        #   sevenInch:  7.6" Foldable main screen   1768x2208
        #   tenInch:    Nexus 9                     1536x2048
        # Style:
        #   [ ] Shadow  [x] Screen Glare
        upload_to_play_store(
            skip_upload_aab: true,
            skip_upload_metadata: true,
            skip_upload_images: true,
            skip_upload_changelogs: true
        )
    when "full"
        # Upload All
        gradle(task: "clean app:bundleRelease")
        upload_to_play_store
    else
        # Upload new version
        gradle(task: "clean app:bundleRelease")
        upload_to_play_store(
            skip_upload_metadata: true,
            skip_upload_images: true,
            skip_upload_screenshots: true
        )
    end
  end
end
