import { PluginPhase, TelemetryOptions, ToPlugin } from "../../shared/src/plugin.js";
import { Plugin } from "../../plugin/plugin.js";
import { PluginManifest } from "../../registry/types.js";
import { ServerConfig } from "./types.js";
import express from "express";
import { Server } from "node:http";

//#region src/plugins/server/index.d.ts

/**
 * Server plugin for the AppKit.
 *
 * This plugin is responsible for starting the server and serving the static files.
 * It also handles the remote tunneling for development purposes.
 *
 * @example
 * ```ts
 * createApp({
 *   plugins: [server(), telemetryExamples(), analytics({})],
 * });
 * ```
 *
 */
declare class ServerPlugin extends Plugin {
  static DEFAULT_CONFIG: {
    autoStart: boolean;
    host: string;
    port: number;
  };
  /** Plugin manifest declaring metadata and resource requirements */
  static manifest: PluginManifest;
  name: "server";
  private serverApplication;
  private server;
  private viteDevServer?;
  private remoteTunnelController?;
  protected config: ServerConfig;
  private serverExtensions;
  static phase: PluginPhase;
  constructor(config: ServerConfig);
  /** Setup the server plugin. */
  setup(): Promise<void>;
  /** Get the server configuration. */
  getConfig(): {
    [key: string]: unknown;
    port?: number;
    staticPath?: string;
    autoStart?: boolean;
    host?: string;
    name?: string;
    telemetry?: TelemetryOptions;
  };
  /** Check if the server should auto start. */
  shouldAutoStart(): boolean | undefined;
  /**
   * Start the server.
   *
   * This method starts the server and sets up the frontend.
   * It also sets up the remote tunneling if enabled.
   *
   * @returns The express application.
   */
  start(): Promise<express.Application>;
  /**
   * Get the low level node.js http server instance.
   *
   * Only use this method if you need to access the server instance for advanced usage like a custom websocket server, etc.
   *
   * @throws {Error} If the server is not started or autoStart is true.
   * @returns {HTTPServer} The server instance.
   */
  getServer(): Server;
  /**
   * Extend the server with custom routes or middleware.
   *
   * @param fn - A function that receives the express application.
   * @returns The server plugin instance for chaining.
   * @throws {Error} If autoStart is true.
   */
  extend(fn: (app: express.Application) => void): this;
  /**
   * Setup the routes with the plugins.
   *
   * This method goes through all the plugins and injects the routes into the server application.
   * Returns a map of plugin names to their registered named endpoints.
   */
  private extendRoutes;
  /**
   * Setup frontend serving based on environment:
   * - If staticPath is explicitly provided: use static server
   * - Dev mode (no staticPath): Vite for HMR
   * - Production (no staticPath): Static files auto-detected
   */
  private setupFrontend;
  private static findStaticPath;
  private logStartupInfo;
  private _gracefulShutdown;
  /**
   * Returns the public exports for the server plugin.
   * Exposes server management methods.
   */
  exports(): {
    /** Start the server */
    start: () => Promise<express.Application>;
    /** Extend the server with custom routes or middleware */
    extend(fn: (app: express.Application) => void): /*elided*/any;
    /** Get the underlying HTTP server instance */
    getServer: () => Server;
    /** Get the server configuration */
    getConfig: () => {
      [key: string]: unknown;
      port?: number;
      staticPath?: string;
      autoStart?: boolean;
      host?: string;
      name?: string;
      telemetry?: TelemetryOptions;
    };
  };
}
/**
 * @internal
 */
declare const server: ToPlugin<typeof ServerPlugin, ServerConfig, "server">;
//#endregion
export { server };
//# sourceMappingURL=index.d.ts.map