fastlane_version '2.206.2'

desc 'test lane'
lane :test do
  print "TEST SUCCESSFUL!"
end

platform :ios do

 desc 'Fetch certificates and provisioning profiles'
 lane :certificates do
     match(type: 'development')
     match(type: "appstore")
 end

 desc 'Build the iOS application.'
 lane :build do
    sh("ns", "prepare", "ios", "--release", "--clean", "--env.production")

    match(type: "appstore")

    build_app(
      scheme: ENV["APP_NAME"],
      workspace: ENV["XC_WORKSPACE_REL_PATH"],
      export_method: "app-store"
    )
 end

 desc 'Ship to Testflight.'
 lane :beta do
     build

     upload_to_testflight(
       beta_app_feedback_email: ENV["CONTACT_EMAIL"],
       beta_app_description: ENV["BETA_DESCRIPTION"],
       demo_account_required: false,
       distribute_external: true,
       groups: ["beta testers"],
       notify_external_testers: true,
       changelog: ENV["CHANGELOG"],
       beta_app_review_info: {
         contact_email: ENV["CONTACT_EMAIL"],
         contact_first_name: ENV["CONTACT_FIRST_NAME"],
         contact_last_name: ENV["CONTACT_LAST_NAME"],
         contact_phone: ENV["CONTACT_PHONE"],
         demo_account_name: "",
         demo_account_password: "",
         notes: ENV["REVIEW_NOTES"]
       },
     )
 end

end

platform :android do

 desc 'Build the Android application.'
 lane :build do
     sh("ns", "build", "android", "--release", "--clean", "--env.production", "--aab",
         "--key-store-path=" + ENV["KEY_STORE_FILE"],
         "--key-store-password=" +  ENV["KEY_STORE_PASSWORD"],
         "--key-store-alias=" + ENV["KEY_STORE_ALIAS"],
         "--key-store-alias-password=" + ENV["KEY_STORE_ALIAS_PASSWORD"]
       )
 end

 desc 'Ship to Playstore Alpha track.'
 lane :alpha do
    upload_to_play_store(
        track: 'alpha',
        json_key: ENV["PATH_TO_PLAY_STORE_UPLOADER_JSON_KEY"],
        package_name: ENV["APP_BUNDLE_ID"],
        version_code: ENV["VERSION_CODE"],
        aab: "platforms/android/app/build/outputs/bundle/release/app-release.aab"
    )
 end

end
