import { Injectable } from '@nestjs/common';
import {
  type AiRuntimeConfig,
  type IAIConfigProvider,
} from '@modules/shared';
import { SystemSettingsService } from '../../application/services/system-settings.service';

/**
 * Adapter that exposes the admin-owned `SystemSettingsService` through the
 * shared `IAIConfigProvider` port. Lets analytics (and any other module)
 * read AI runtime config without importing AdminModule (A-09).
 */
@Injectable()
export class SystemSettingsAiConfigProvider implements IAIConfigProvider {
  constructor(private readonly systemSettings: SystemSettingsService) {}

  async getAiConfig(): Promise<AiRuntimeConfig> {
    const settings = await this.systemSettings.getAiSettings();
    return {
      apiUrl: settings.apiUrl,
      apiKey: settings.apiKey,
      model: settings.model,
    };
  }
}
