import Foundation
import Capacitor

/**
 * Please read the Capacitor iOS Plugin Development Guide
 * here: https://capacitorjs.com/docs/plugins/ios
 */


import MoEngagePluginBase
import MoEngagePluginGeofence

@objc(MoECapacitorGeofencePlugin)
public class MoECapacitorGeofencePlugin: CAPPlugin , CAPBridgedPlugin {

    public let identifier = "MoECapacitorGeofencePlugin" 
    public let jsName = "MoECapacitorGeofence" 
    public let pluginMethods: [CAPPluginMethod] = [
        CAPPluginMethod(name: "startGeofenceMonitoring", returnType: CAPPluginReturnNone),
        CAPPluginMethod(name: "stopGeofenceMonitoring", returnType: CAPPluginReturnNone)
    ]

    @objc func startGeofenceMonitoring(_ call: CAPPluginCall) {
        guard let appId = call.getString("appId")
        else
        {
            print("Account identifier is invalid")
            return
        }
        let accountPayload = [MoEngagePluginConstants.General.accountMeta: MoEngagePluginUtils.createAccountPayload(identifier: appId)]
        MoEngagePluginGeofenceBridge.sharedInstance.startGeofenceMonitoring(accountPayload)
    }
    
    @objc func stopGeofenceMonitoring(_ call: CAPPluginCall) {
        guard let appId = call.getString("appId")
        else
        {
            print("Account identifier is invalid")
            return
        }
        let accountPayload = [MoEngagePluginConstants.General.accountMeta: MoEngagePluginUtils.createAccountPayload(identifier: appId)]
        MoEngagePluginGeofenceBridge.sharedInstance.stopGeofenceMonitoring(accountPayload)
    }
}
