import UIKit
import Flutter
import workmanager_apple

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

    // Ensure plugins are registered in the background isolate
    WorkmanagerPlugin.setPluginRegistrantCallback { registry in
      GeneratedPluginRegistrant.register(with: registry)
    }

    // Register your background processing tasks (you already have these)
    WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "com.logiit.backgroundSync")
    WorkmanagerPlugin.registerBGProcessingTask(withIdentifier: "com.logiit.manualSync")

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
