class BasePlugin {
  dependencies;
  context;
  status = { state: "uninitialized" };
  metrics = {
    eventsEmitted: 0,
    eventsReceived: 0,
    errors: 0
  };
  startTime;
  async initialize(context) {
    this.context = context;
    this.status = { state: "initialized" };
    await this.onInitialize();
  }
  async start() {
    this.status = { state: "starting" };
    this.startTime = Date.now();
    await this.onStart();
    this.status = { state: "running", lastActivity: Date.now() };
  }
  async stop() {
    this.status = { state: "stopping" };
    await this.onStop();
    this.status = { state: "stopped" };
  }
  async shutdown() {
    if (this.status.state === "running") {
      await this.stop();
    }
    await this.onShutdown();
    this.status = { state: "uninitialized" };
  }
  getStatus() {
    return { ...this.status };
  }
  getMetrics() {
    return {
      ...this.metrics,
      startTime: this.startTime,
      uptime: this.startTime ? Date.now() - this.startTime : 0
    };
  }
  validateConfig(config) {
    const errors = [];
    const warnings = [];
    if (config.name !== this.name) {
      errors.push(`Config name '${config.name}' doesn't match plugin name '${this.name}'`);
    }
    const customValidation = this.onValidateConfig(config);
    if (customValidation.errors) errors.push(...customValidation.errors);
    if (customValidation.warnings) warnings.push(...customValidation.warnings);
    return {
      valid: errors.length === 0,
      errors: errors.length > 0 ? errors : void 0,
      warnings: warnings.length > 0 ? warnings : void 0
    };
  }
  emit(eventType, data) {
    if (!this.context) throw new Error("Plugin not initialized");
    this.context.eventBus.emit({
      type: eventType,
      source: this.name,
      data
    });
    this.metrics.eventsEmitted++;
    this.status.lastActivity = Date.now();
  }
  on(eventType, handler) {
    if (!this.context) throw new Error("Plugin not initialized");
    this.context.eventBus.on(eventType, async (event) => {
      this.metrics.eventsReceived++;
      this.status.lastActivity = Date.now();
      try {
        await handler(event);
      } catch (error) {
        this.metrics.errors++;
        this.status.error = error;
        console.error(`Plugin ${this.name} error handling ${eventType}:`, error);
      }
    });
  }
}
export {
  BasePlugin
};
//# sourceMappingURL=plugin-interface.js.map
