import type { AutoplayPayload } from "@/lib/autoplay-ipc";
import type { LinkMetadata } from "@/lib/link-metadata";

export interface ScreenSource {
  id: string;
  name: string;
  thumbnailDataUrl: string;
  appIconDataUrl: string | null;
}

export interface Platform {
  kind: "electron" | "web";

  window: {
    minimize: () => void;
    maximize: () => void;
    fullscreen: () => void;
    close: () => void;
    onMaximizeChange: (cb: (m: boolean) => void) => () => void;
    platform: "darwin" | "win32" | "linux" | "web";
  };

  huddle: {
    isSupported: boolean;
    open: (args: { token: string; serverUrl: string }) => void;
    close: () => void;
    getScreenSources: () => Promise<ScreenSource[]>;
  };

  screenRecord: {
    isSupported: boolean;
    start: () => void;
    stop: () => void;
    cancel: () => void;
    onStopRequested: (cb: () => void) => () => void;
    getScreenSources: () => Promise<ScreenSource[]>;
  };

  autoplay: {
    play: (payload: AutoplayPayload) => void;
    dismiss: () => void;
    navigate: (d: { networkId: string; streamId: string }) => void;
    onPlay: (cb: (payload: AutoplayPayload) => void) => () => void;
    onStop: (cb: () => void) => () => void;
    onNavigate: (cb: (d: { networkId: string; streamId: string }) => void) => () => void;
  };

  link: {
    fetchMetadata: (url: string) => Promise<LinkMetadata | null>;
    openExternal: (url: string) => Promise<void>;
  };

  attachment: {
    download: (url: string, filename?: string) => void;
  };

  app: {
    setDockBadge: (count: number) => void;
    getVersion: () => Promise<string>;
  };
}

export const DESKTOP_DOWNLOAD_URL = "https://flowylabs.ai/llink/download";
