import Flutter
import UIKit
import YandexMapsMobile

@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    let apiKey =
      (Bundle.main.object(forInfoDictionaryKey: "YandexMapKitApiKey") as? String ?? "")
      .trimmingCharacters(in: .whitespacesAndNewlines)
    #if DEBUG
    if apiKey.isEmpty || apiKey.contains("$(") {
      assertionFailure(
        "YandexMapKitApiKey пустой или не подставился из xcconfig — проверь YANDEX_MAPKIT_API_KEY в ios/Flutter/*.xcconfig"
      )
    }
    #endif
    YMKMapKit.setLocale(Locale.current.identifier)
    YMKMapKit.setApiKey(apiKey)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
    GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
  }
}
