import { Injectable, Logger } from '@nestjs/common';
import { EngineRegistry } from '../../infrastructure/engines/engine-registry';
import { AgentEngineType } from '../../domain/value-objects/agent-engine-type.vo';
import { SwitchEnginePort } from '../../domain/ports/inbound/switch-engine.port';

@Injectable()
export class SwitchEngineUseCase implements SwitchEnginePort {
  private readonly logger = new Logger(SwitchEngineUseCase.name);

  constructor(private readonly engineRegistry: EngineRegistry) {}

  async switchEngine(engineType: string): Promise<void> {
    const engine = this.engineRegistry.switchEngine(engineType as AgentEngineType);
    this.logger.log(`Switched to engine: ${engine.engineType}`);
  }

  getActiveEngine(): string {
    const engine = this.engineRegistry.getActiveEngine();
    return engine.engineType;
  }

  listAvailable(): string[] {
    return this.engineRegistry.listAvailable();
  }
}
