import {
  THEME_ROUTE_HANDLERS,
  PLUGIN_ROUTE_HANDLERS
} from "@nextsparkjs/registries/route-handlers";
class RouteHandlerService {
  // ==================== Theme Route Methods ====================
  /**
   * Get theme route handler by route key and HTTP method
   *
   * @param routeKey - Route key in format 'theme-name/route-path'
   * @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
   * @returns RouteHandler function or null if not found
   *
   * @example
   * const handler = RouteHandlerService.getThemeHandler('default/custom', 'GET')
   * if (handler) {
   *   const response = await handler(request, { params: Promise.resolve({}) })
   * }
   */
  static getThemeHandler(routeKey, method) {
    const handlers = THEME_ROUTE_HANDLERS[routeKey];
    if (!handlers) return null;
    return handlers[method] || null;
  }
  /**
   * Get all registered theme route keys
   *
   * @returns Array of route keys
   *
   * @example
   * const keys = RouteHandlerService.getThemeKeys()
   * // ['default/custom', 'default/webhook', ...]
   */
  static getThemeKeys() {
    return Object.keys(THEME_ROUTE_HANDLERS);
  }
  /**
   * Check if a theme route exists
   *
   * @param routeKey - Route key in format 'theme-name/route-path'
   * @param method - Optional HTTP method to check
   * @returns true if route (and optionally method) exists
   *
   * @example
   * // Check if route exists (any method)
   * RouteHandlerService.hasThemeRoute('default/custom') // true
   *
   * // Check if route exists with specific method
   * RouteHandlerService.hasThemeRoute('default/custom', 'POST') // false
   */
  static hasThemeRoute(routeKey, method) {
    const handlers = THEME_ROUTE_HANDLERS[routeKey];
    if (!handlers) return false;
    if (method) return handlers[method] !== void 0;
    return true;
  }
  /**
   * Get count of registered theme routes
   *
   * @returns Number of theme route keys
   */
  static getThemeCount() {
    return Object.keys(THEME_ROUTE_HANDLERS).length;
  }
  /**
   * Get all theme handlers (full registry)
   *
   * @returns The complete THEME_ROUTE_HANDLERS registry
   */
  static getAllThemeHandlers() {
    return THEME_ROUTE_HANDLERS;
  }
  // ==================== Plugin Route Methods ====================
  /**
   * Get plugin route handler by route key and HTTP method
   *
   * @param routeKey - Route key in format 'plugin-name/route-path'
   * @param method - HTTP method (GET, POST, PUT, DELETE, PATCH)
   * @returns RouteHandler function or null if not found
   *
   * @example
   * const handler = RouteHandlerService.getPluginHandler('ai/generate', 'POST')
   * if (handler) {
   *   const response = await handler(request, { params: Promise.resolve({}) })
   * }
   */
  static getPluginHandler(routeKey, method) {
    const handlers = PLUGIN_ROUTE_HANDLERS[routeKey];
    if (!handlers) return null;
    return handlers[method] || null;
  }
  /**
   * Get all registered plugin route keys
   *
   * @returns Array of route keys
   *
   * @example
   * const keys = RouteHandlerService.getPluginKeys()
   * // ['ai/generate', 'ai/embeddings', ...]
   */
  static getPluginKeys() {
    return Object.keys(PLUGIN_ROUTE_HANDLERS);
  }
  /**
   * Check if a plugin route exists
   *
   * @param routeKey - Route key in format 'plugin-name/route-path'
   * @param method - Optional HTTP method to check
   * @returns true if route (and optionally method) exists
   *
   * @example
   * // Check if route exists (any method)
   * RouteHandlerService.hasPluginRoute('ai/generate') // true
   *
   * // Check if route exists with specific method
   * RouteHandlerService.hasPluginRoute('ai/generate', 'POST') // true
   */
  static hasPluginRoute(routeKey, method) {
    const handlers = PLUGIN_ROUTE_HANDLERS[routeKey];
    if (!handlers) return false;
    if (method) return handlers[method] !== void 0;
    return true;
  }
  /**
   * Get count of registered plugin routes
   *
   * @returns Number of plugin route keys
   */
  static getPluginCount() {
    return Object.keys(PLUGIN_ROUTE_HANDLERS).length;
  }
  /**
   * Get all plugin handlers (full registry)
   *
   * @returns The complete PLUGIN_ROUTE_HANDLERS registry
   */
  static getAllPluginHandlers() {
    return PLUGIN_ROUTE_HANDLERS;
  }
  // ==================== Combined Methods ====================
  /**
   * Get total count of all registered routes (theme + plugin)
   *
   * @returns Total number of route keys
   */
  static getTotalCount() {
    return this.getThemeCount() + this.getPluginCount();
  }
}
const getThemeRouteHandler = RouteHandlerService.getThemeHandler;
const getPluginRouteHandler = RouteHandlerService.getPluginHandler;
const getThemeRouteKeys = RouteHandlerService.getThemeKeys;
const getPluginRouteKeys = RouteHandlerService.getPluginKeys;
export {
  RouteHandlerService,
  getPluginRouteHandler,
  getPluginRouteKeys,
  getThemeRouteHandler,
  getThemeRouteKeys
};
