// Global type declarations for SparkBun browser environment

interface SparkBunEncryptResult {
  encryptedData: string;
  iv: string;
  tag: string;
}

interface SparkBunBridge {
  receiveMessageFromHost: (msg: unknown) => void;
  receiveInternalMessageFromHost: (msg: unknown) => void;
  receiveMessageFromBun: (msg: unknown) => void;
  receiveInternalMessageFromBun: (msg: unknown) => void;
}

interface MessageHandler {
  postMessage: (msg: string) => void;
}

declare global {
  interface Window {
    __sparkbunWebviewId: number;
    __sparkbunWindowId: number;
    __sparkbunRpcSocketPort: number;
    __sparkbunHostSocketPort?: number;
    __sparkbun?: SparkBunBridge;
    __sparkbunPendingHostMessages?: unknown[];
    __sparkbun_encrypt: (msg: string) => Promise<SparkBunEncryptResult>;
    __sparkbun_decrypt: (encryptedData: string, iv: string, tag: string) => Promise<string>;
    __sparkbunInternalBridge?: MessageHandler;
    __sparkbunHostBridge?: MessageHandler;
    __sparkbunBunBridge?: MessageHandler;
  }
}

export {};
