import { ComponentType } from 'react';

/**
 * Route configuration for plugins
 */
export interface RouteConfig {
  path: string;
  component: ComponentType<any>;
  exact?: boolean;
  permissions?: string[];
  layout?: ComponentType<any>;
}

/**
 * Component registry for plugins
 */
export interface ComponentConfig {
  [key: string]: ComponentType<any>;
}

/**
 * Service configuration for plugins
 */
export interface ServiceConfig {
  token: string;
  factory: () => any;
  singleton?: boolean;
}

/**
 * Permission definition
 */
export interface Permission {
  id: string;
  name: string;
  description: string;
  category?: string;
}

/**
 * Plugin metadata
 */
export interface PluginMetadata {
  id: string;
  name: string;
  version: string;
  description?: string;
  author?: string;
  dependencies?: string[];
  optionalDependencies?: string[];
  permissions?: Permission[];
}

/**
 * Plugin interface
 */
export interface IPlugin {
  /**
   * Plugin metadata
   */
  readonly metadata: PluginMetadata;
  
  /**
   * Plugin activation
   */
  activate(): Promise<void>;
  
  /**
   * Plugin deactivation
   */
  deactivate(): Promise<void>;
  
  /**
   * Get plugin routes
   */
  getRoutes?(): RouteConfig[];
  
  /**
   * Get plugin components
   */
  getComponents?(): ComponentConfig;
  
  /**
   * Get plugin services
   */
  getServices?(): ServiceConfig[];
  
  /**
   * Plugin health check
   */
  isHealthy?(): Promise<boolean>;
  
  /**
   * Plugin configuration
   */
  configure?(config: Record<string, any>): Promise<void>;
}

/**
 * Plugin registry interface
 */
export interface IPluginRegistry {
  /**
   * Register a plugin
   */
  register(plugin: IPlugin): Promise<void>;
  
  /**
   * Unregister a plugin
   */
  unregister(pluginId: string): Promise<void>;
  
  /**
   * Get plugin by ID
   */
  getPlugin(pluginId: string): IPlugin | null;
  
  /**
   * Get all registered plugins
   */
  getAllPlugins(): IPlugin[];
  
  /**
   * Get active plugins
   */
  getActivePlugins(): IPlugin[];
  
  /**
   * Check if plugin is active
   */
  isActive(pluginId: string): boolean;
  
  /**
   * Activate plugin
   */
  activate(pluginId: string): Promise<void>;
  
  /**
   * Deactivate plugin
   */
  deactivate(pluginId: string): Promise<void>;
}

/**
 * Feature module interface (extends plugin)
 */
export interface IFeatureModule extends IPlugin {
  /**
   * Module installation
   */
  install(): Promise<void>;
  
  /**
   * Module uninstallation
   */
  uninstall(): Promise<void>;
  
  /**
   * Module migration
   */
  migrate?(version: string): Promise<void>;
}