package com.example.nexilissamplecodeionic;

import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

import io.nexilis.service.API;

@CapacitorPlugin(name = "NativeCap")
public class NativePlugin extends Plugin {

  @PluginMethod
  public void openContactCenter(PluginCall call) {
    String response = API.openContactCenter();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openChat(PluginCall call) {
    String response = API.openChat();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openCall(PluginCall call) {
    String response = API.openCall();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openStreaming(PluginCall call) {
    String response = API.openLiveStreaming();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openChatGPT(PluginCall call) {
    String response = API.openSmartChatbot();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openSetOfficer(PluginCall call) {
    String response = API.openSetAsOfficerForm();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openSettings(PluginCall call) {
    API.openSettings();
  }

  @PluginMethod
  public void openProfile(PluginCall call) {
    API.openProfile();
  }

  @PluginMethod
  public void openContactCenterChat(PluginCall call) {
    int category = call.getInt("category", 0);
    String response = API.openContactCenter(0, category);
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openContactCenterAudioCall(PluginCall call) {
    int category = call.getInt("category", 0);
    String response = API.openContactCenter(1, category);
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openContactCenterVideoCall(PluginCall call) {
    int category = call.getInt("category", 0);
    String response = API.openContactCenter(2, category);
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void adminSignIn(PluginCall call) {
    if (!call.getData().has("pwd")) {
      call.reject("Must provide an pwd");
      return;
    }
    String pwd = call.getString("pwd");
    String response = API.signInAdmin(pwd);
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openWhiteboard(PluginCall call) {
    String response = API.openWhiteboard();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }

  @PluginMethod
  public void openSecureFolder(PluginCall call) {
    String response = API.openSecureFolder();
    JSObject ret = new JSObject();
    ret.put("response", response);
    call.resolve(ret);
  }
}
