/**
 * Base interface for all services in the application
 * Provides common service lifecycle methods
 */
export interface IService {
  /**
   * Service identifier
   */
  readonly id: string;
  
  /**
   * Service name for debugging and logging
   */
  readonly name: string;
  
  /**
   * Initialize the service
   * Called when service is first resolved from container
   */
  initialize?(): Promise<void>;
  
  /**
   * Cleanup resources when service is destroyed
   */
  destroy?(): Promise<void>;
  
  /**
   * Health check for the service
   */
  isHealthy?(): Promise<boolean>;
}

/**
 * Base service implementation
 */
export abstract class BaseService implements IService {
  abstract readonly id: string;
  abstract readonly name: string;
  
  protected _initialized = false;
  
  async initialize(): Promise<void> {
    if (this._initialized) return;
    
    await this.onInitialize();
    this._initialized = true;
  }
  
  async destroy(): Promise<void> {
    if (!this._initialized) return;
    
    await this.onDestroy();
    this._initialized = false;
  }
  
  async isHealthy(): Promise<boolean> {
    return this._initialized;
  }
  
  protected async onInitialize(): Promise<void> {
    // Override in derived classes
  }
  
  protected async onDestroy(): Promise<void> {
    // Override in derived classes
  }
}