/// <reference types="vite/client" />

declare module 'browser-encrypt-attachment' {
  export interface EncryptedAttachmentInfo {
    v: string;
    key: {
      alg: string;
      key_ops: string[];
      kty: string;
      k: string;
      ext: boolean;
    };
    iv: string;
    hashes: {
      [alg: string]: string;
    };
  }

  export interface EncryptedAttachment {
    data: ArrayBuffer;
    info: EncryptedAttachmentInfo;
  }

  export function encryptAttachment(dataBuffer: ArrayBuffer): Promise<EncryptedAttachment>;

  export function decryptAttachment(
    dataBuffer: ArrayBuffer,
    info: EncryptedAttachmentInfo
  ): Promise<ArrayBuffer>;
}

declare module '*.svg' {
  const content: string;
  export default content;
}

interface PluginAPI {
  getPath: () => Promise<{ success: boolean; data?: string; error?: string }>;
  download: (
    pluginId: string,
    downloadUrl: string,
    name: string
  ) => Promise<{ success: boolean; data?: { path: string }; error?: string }>;
  list: () => Promise<{
    success: boolean;
    data?: Array<{ id: string; name: string; installedDate: string; path: string }>;
    error?: string;
  }>;
  uninstall: (pluginId: string) => Promise<{ success: boolean; error?: string }>;
  readPluginCode: (pluginId: string) => Promise<{ success: boolean; data?: string; error?: string }>;
}

interface ElectronAPI {
  platform?: string;
  arch?: string;
  clipboard?: {
    writeText: (text: string) => void;
  };
  plugins?: PluginAPI;
  protocol?: {
    getStatus: () => Promise<{
      success: boolean;
      data?: {
        scheme: string;
        platform: string;
        isDefault: boolean;
        before: boolean;
        registerCall: boolean;
        error: string | null;
        windows: null | {
          userChoiceProgId: string | null;
          userChoiceCommand: string | null;
          hkcuCommand: string | null;
          hklmCommand: string | null;
        };
      };
      error?: string;
    }>;
    repair: () => Promise<{
      success: boolean;
      data?: {
        scheme: string;
        platform: string;
        isDefault: boolean;
        before: boolean;
        registerCall: boolean;
        error: string | null;
        windows: null | {
          userChoiceProgId: string | null;
          userChoiceCommand: string | null;
          hkcuCommand: string | null;
          hklmCommand: string | null;
        };
      };
      error?: string;
    }>;
  };
}

declare global {
  interface Window {
    electron?: ElectronAPI;
  }
}

export {};
