import { Module, Global } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { AuthModule } from "../auth/auth.module";
import { MosaicTelemetryService } from "./mosaic-telemetry.service";
import { PredictionService } from "./prediction.service";
import { MosaicTelemetryController } from "./mosaic-telemetry.controller";

/**
 * Global module providing Mosaic Telemetry integration via @mosaicstack/telemetry-client.
 *
 * Tracks task completion events and provides crowd-sourced predictions for
 * token usage, cost estimation, and quality metrics.
 *
 * **This is separate from the OpenTelemetry (OTEL) TelemetryModule** which
 * handles distributed request tracing. This module is specifically for
 * Mosaic Stack's own telemetry aggregation service.
 *
 * Configuration via environment variables:
 * - MOSAIC_TELEMETRY_ENABLED (boolean, default: true)
 * - MOSAIC_TELEMETRY_SERVER_URL (string)
 * - MOSAIC_TELEMETRY_API_KEY (string, 64-char hex)
 * - MOSAIC_TELEMETRY_INSTANCE_ID (string, UUID)
 * - MOSAIC_TELEMETRY_DRY_RUN (boolean, default: false)
 *
 * @example
 * ```typescript
 * // In any service (no need to import module — it's global):
 * @Injectable()
 * export class MyService {
 *   constructor(private readonly telemetry: MosaicTelemetryService) {}
 * }
 * ```
 */
@Global()
@Module({
  imports: [ConfigModule, AuthModule],
  controllers: [MosaicTelemetryController],
  providers: [MosaicTelemetryService, PredictionService],
  exports: [MosaicTelemetryService, PredictionService],
})
export class MosaicTelemetryModule {}
