import UIKit
import Flutter
import NexilisLite

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, ConnectDelegate {
    func onSuccess(userId: String) {
        
    }
    
    func onFailed(error: String) {
        
    }
    
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    //FLOATING
    APIS.connect(apiKey: "***REPLACE***WITH***YOUR***ACCOUNT***", delegate: self, showButton: false)
    let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    let batteryChannel = FlutterMethodChannel(name: "nativeChannel", binaryMessenger: controller.binaryMessenger)
    batteryChannel.setMethodCallHandler({(call: FlutterMethodCall, result: FlutterResult) -> Void in
        // Note: this method is invoked on the UI thread.
        if call.method == "openContactCenter" {
            APIS.openContactCenter()
        } else if call.method == "openInstantMessaging" {
            APIS.openChat()
        } else if call.method == "openCall" {
            APIS.openCall()
        } else if call.method == "openStreaming" {
            APIS.openStreaming()
        } else if call.method == "openWhiteboard" {
            APIS.openWhiteboard()
        } else if call.method == "openSettings" {
            APIS.openSetting()
        } else if call.method == "openSetOfficer" {
            APIS.openSetAsOfficerForm()
        } else if call.method == "openContactCenterChat" {
            var category: Int?
            if let arguments = call.arguments as? [String: Any],
                let param1 = arguments["category"] as? Int {
                category = param1
            }
            APIS.openContactCenter(media: 0, category: category)
        } else if call.method == "openContactCenterAudioCall" {
            var category: Int?
            if let arguments = call.arguments as? [String: Any],
                let param1 = arguments["category"] as? Int {
                category = param1
            }
            APIS.openContactCenter(media: 1, category: category)
        } else if call.method == "openContactCenterVideoCall" {
            var category: Int?
            if let arguments = call.arguments as? [String: Any],
                let param1 = arguments["category"] as? Int {
                category = param1
            }
            APIS.openContactCenter(media: 2, category: category)
        } else if call.method == "signInAdmin" {
            var pwd: String?
            if let arguments = call.arguments as? [String: Any],
                let param1 = arguments["pwd"] as? String {
                pwd = param1
            }
            APIS.signInAdmin(password: pwd ?? "")
        } else {
            result(FlutterMethodNotImplemented)
        }
    })
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
