import { Module } from "@nestjs/common";
import { OllamaController } from "./ollama.controller";
import { OllamaService, OllamaConfig } from "./ollama.service";

/**
 * Factory function to create Ollama configuration from environment variables
 */
function createOllamaConfig(): OllamaConfig {
  const mode = (process.env.OLLAMA_MODE ?? "local") as "local" | "remote";
  const endpoint = process.env.OLLAMA_ENDPOINT ?? "http://localhost:11434";
  const model = process.env.OLLAMA_MODEL ?? "llama3.2";
  const timeout = parseInt(process.env.OLLAMA_TIMEOUT ?? "30000", 10);

  return {
    mode,
    endpoint,
    model,
    timeout,
  };
}

/**
 * Module for Ollama integration
 * Provides AI capabilities via local or remote Ollama instances
 */
@Module({
  controllers: [OllamaController],
  providers: [
    {
      provide: "OLLAMA_CONFIG",
      useFactory: createOllamaConfig,
    },
    OllamaService,
  ],
  exports: [OllamaService],
})
export class OllamaModule {}
