import { StoryIndex } from "storybook/internal/types";
import { WebSocketServer } from "ws";

//#region src/metro/channelServer.d.ts
interface ChannelServerSecureOptions {
  ca?: string | Buffer | Array<string | Buffer>;
  cert?: string | Buffer | Array<string | Buffer>;
  key?: string | Buffer | Array<string | Buffer>;
  passphrase?: string;
}
/**
 * Options for creating a channel server.
 */
interface ChannelServerOptions {
  /**
   * The port the server will listen on.
   */
  port?: number;
  /**
   * The host the server will bind to.
   */
  host?: string;
  /**
   * The path to the Storybook config folder.
   */
  configPath: string;
  /**
   * Whether to enable MCP (Model Context Protocol) server support.
   * When enabled, adds an /mcp endpoint.
   */
  experimental_mcp?: boolean;
  /**
   * Whether to enable WebSocket support.
   * When false, starts only the HTTP server endpoints.
   */
  websockets?: boolean;
  /**
   * Whether to use HTTPS/WSS for the channel server.
   * When true, valid TLS credentials must be provided via `ssl`.
   */
  secured?: boolean;
  /**
   * TLS credentials used when `secured` is true.
   */
  ssl?: ChannelServerSecureOptions;
  /**
   * Whether the channel server should keep the Node.js process alive.
   * When false, the server is unref'd.
   * Defaults to false.
   */
  keepNodeProcessAlive?: boolean;
}
/**
 * Creates a channel server for syncing storybook instances and sending events.
 * The server provides both WebSocket and REST endpoints:
 * - WebSocket: broadcasts all received messages to all connected clients
 * - POST /send-event: sends an event to all WebSocket clients
 * - POST /select-story-sync/{storyId}: sets the current story and waits for a storyRendered event
 * - GET /index.json: returns the story index built from story files
 * - POST /mcp: MCP endpoint for AI agent integration (when experimental_mcp option is enabled)
 *
 * @param options - Configuration options for the channel server.
 * @param options.port - The port to listen on.
 * @param options.host - The host to bind to.
 * @param options.configPath - The path to the Storybook config folder.
 * @param options.experimental_mcp - Whether to enable MCP server support.
 * @param options.websockets - Whether to enable WebSocket server support.
 * @param options.secured - Whether to use HTTPS/WSS for the channel server.
 * @param options.ssl - TLS credentials used when `secured` is true.
 * @param options.keepAlive - Whether the channel server should keep the Node.js process alive.
 * @returns The created WebSocketServer instance, or null when websockets are disabled.
 */
declare function createChannelServer({
  port,
  host,
  configPath,
  experimental_mcp,
  websockets,
  secured,
  ssl,
  keepNodeProcessAlive
}: ChannelServerOptions): WebSocketServer | null;
//#endregion
//#region src/metro/buildIndex.d.ts
declare function buildIndex({
  configPath
}: {
  configPath: string;
}): Promise<StoryIndex>;
//#endregion
export { buildIndex, createChannelServer };