# This file contains the fastlane.tools configuration
# for the iOS half of the Skip app.
# You can find the documentation at https://docs.fastlane.tools

default_platform(:ios)

lane :assemble do |options|
  # only build the iOS side of the app
  ENV["SKIP_ZERO"] = "true"

  # Scope manual signing to just the app target - the SPM package's own
  # generated targets (PediFoods, pedi-foods_PediFoods) explicitly don't
  # support provisioning profiles and must stay on Automatic, so a blanket
  # xcargs override breaks them.
  if ENV["DEVELOPMENT_TEAM"]
    update_code_signing_settings(
      use_automatic_signing: false,
      path: "PediFoods.xcodeproj",
      code_sign_identity: "Apple Distribution",
      profile_name: "com.br.pedifoods.app AppStore",
      team_id: ENV["DEVELOPMENT_TEAM"],
      targets: ["PediFoods App"]
    )
  end

  build_app(
    scheme: "PediFoods App",
    sdk: "iphoneos",
    export_method: ENV["BITRISE_DISTRIBUTION_METHOD"] || "app-store",
    xcconfig: "fastlane/AppStore.xcconfig",
    xcargs: "-skipPackagePluginValidation -skipMacroValidation",
    derived_data_path: "../.build/Darwin/DerivedData",
    output_directory: "../.build/fastlane/Darwin",
    skip_archive: ENV["FASTLANE_SKIP_ARCHIVE"] == "YES",
    skip_codesigning: ENV["FASTLANE_SKIP_CODESIGNING"] == "YES"
  )
end

lane :beta do |options|
  desc "Build and upload to TestFlight"

  get_provisioning_profile(api_key_path: "fastlane/apikey.json")

  assemble

  upload_to_testflight(
    api_key_path: "fastlane/apikey.json",
    skip_waiting_for_build_processing: true
  )
end

lane :release do |options|
  desc "Build and release app"

  # see https://docs.fastlane.tools/uploading-app-privacy-details/
  #upload_app_privacy_details_to_app_store(json_path: "fastlane/app_privacy_details.json")

  # if you have an apikey.json file (https://developer.apple.com/documentation/appstoreconnectapi/creating-api-keys-for-app-store-connect-api), fastlane can automatically fetch certificates and the ASC authentication information
  #get_certificates(api_key_path: "fastlane/apikey.json")
  get_provisioning_profile(api_key_path: "fastlane/apikey.json")

  assemble

  upload_to_app_store(
    api_key_path: "fastlane/apikey.json",
    app_rating_config_path: "fastlane/metadata/rating.json",
    release_notes: { default: "Fixes and improvements." }
  )
end

