import UIKit
import Flutter
import Libcore

@main
@objc class AppDelegate: FlutterAppDelegate {
    
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        setupFileManager()
        registerHandlers()
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    func setupFileManager() {
        try? FileManager.default.createDirectory(at: FilePath.workingDirectory, withIntermediateDirectories: true)
        FileManager.default.changeCurrentDirectoryPath(FilePath.sharedDirectory.path)
    }
    
    func registerHandlers() {
        KRMethodHandler.register(with: self.registrar(forPlugin: KRMethodHandler.name)!)
        KRPlatformMethodHandler.register(with: self.registrar(forPlugin: KRPlatformMethodHandler.name)!)
        KRFileMethodHandler.register(with: self.registrar(forPlugin: KRFileMethodHandler.name)!)
        KRStatusEventHandler.register(with: self.registrar(forPlugin: KRStatusEventHandler.name)!)
        KRAlertsEventHandler.register(with: self.registrar(forPlugin: KRAlertsEventHandler.name)!)
        KRLogsEventHandler.register(with: self.registrar(forPlugin: KRLogsEventHandler.name)!)
        KRGroupsEventHandler.register(with: self.registrar(forPlugin: KRGroupsEventHandler.name)!)
        KRActiveGroupsEventHandler.register(with: self.registrar(forPlugin: KRActiveGroupsEventHandler.name)!)
        KRStatsEventHandler.register(with: self.registrar(forPlugin: KRStatsEventHandler.name)!)
    }
}

