import Foundation
import Capacitor
/**
 * Please read the Capacitor iOS Plugin Development Guide
 * here: https://capacitorjs.com/docs/plugins/ios
 */
@objc(Plugin)
public class Plugin: CAPPlugin {
    private let contact = Contact()
    private let screenCapture = PreventCapture()
    
    @objc func addContact(_ call: CAPPluginCall) {
        let name = call.getString("name") ?? ""
        let phone = call.getString("phone") ?? ""
        let email = call.getString("email") ?? ""
        let dept = call.getString("dept") ?? ""
        let ext = call.getString("ext") ?? ""
        
        contact.saveContact(name: name, phone: phone, email: email, dept: dept, ext: ext) { success in
            if success {
                call.resolve([
                    "result": true,
                    "message": "완료"
                ])
            } else {
                call.resolve([
                    "result": false,
                    "message": "존재하는 번호입니다."
                ])
            }
        }
    }
    
    @objc func setScreenCaptureDisabled(_ call: CAPPluginCall) {
        screenCapture.screenCapturePrevent(view: self.bridge?.viewController!.view ?? self.webView!) { success in
            if success {
                call.resolve([
                    "result": true,
                    "message": "완료"
                ])
            } else {
                call.resolve([
                    "result": false,
                    "message": "실패"
                ])
            }
        }
        
    
    }

}

