default_platform(:ios)

platform :ios do
  desc "Build and upload to TestFlight"
  lane :beta do
    # Generate Xcode project from project.yml (one level up from fastlane/)
    sh("cd .. && xcodegen generate --spec project.yml --project .")

    # Set build number from CI run number (passed as env var)
    increment_build_number(
      build_number: ENV["BUILD_NUMBER"] || "1",
      xcodeproj: "LibNovel.xcodeproj"
    )

    # Build the app
    build_app(
      scheme: "LibNovel",
      export_method: "app-store",
      clean: true,
      export_options: {
        provisioningProfiles: {
          "com.kalekber.LibNovel" => ENV["PROVISIONING_PROFILE_NAME"] || "LibNovel Distribution"
        }
      }
    )

    # Upload to TestFlight
    upload_to_testflight(
      skip_waiting_for_build_processing: true
    )
  end
end
