/**
 * Tauri adapter for plugin-owned JSON storage (#139).
 */

import { invoke } from "@tauri-apps/api/core";

import type { JsonValue } from "@/domain";
import type {
  PluginStorageGateway,
  PluginStorageGetInput,
  PluginStorageSetInput,
} from "@/ports";

export class TauriPluginStorageGateway implements PluginStorageGateway {
  get(input: PluginStorageGetInput): Promise<JsonValue | null> {
    return invoke<JsonValue | null>("plugin_storage_get", { input });
  }

  async set(input: PluginStorageSetInput): Promise<void> {
    await invoke("plugin_storage_set", { input });
  }

  delete(input: PluginStorageGetInput): Promise<boolean> {
    return invoke<boolean>("plugin_storage_delete", { input });
  }
}
