import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  UseGuards,
  UsePipes,
  ValidationPipe,
} from "@nestjs/common";
import type { AgentProviderConfig } from "@prisma/client";
import { OrchestratorApiKeyGuard } from "../../common/guards/api-key.guard";
import { OrchestratorThrottlerGuard } from "../../common/guards/throttler.guard";
import { AgentProvidersService } from "./agent-providers.service";
import { CreateAgentProviderDto } from "./dto/create-agent-provider.dto";
import { UpdateAgentProviderDto } from "./dto/update-agent-provider.dto";

@Controller("agent-providers")
@UseGuards(OrchestratorApiKeyGuard, OrchestratorThrottlerGuard)
export class AgentProvidersController {
  constructor(private readonly agentProvidersService: AgentProvidersService) {}

  @Get()
  async list(): Promise<AgentProviderConfig[]> {
    return this.agentProvidersService.list();
  }

  @Get(":id")
  async getById(@Param("id") id: string): Promise<AgentProviderConfig> {
    return this.agentProvidersService.getById(id);
  }

  @Post()
  @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
  async create(@Body() dto: CreateAgentProviderDto): Promise<AgentProviderConfig> {
    return this.agentProvidersService.create(dto);
  }

  @Patch(":id")
  @UsePipes(new ValidationPipe({ transform: true, whitelist: true }))
  async update(
    @Param("id") id: string,
    @Body() dto: UpdateAgentProviderDto
  ): Promise<AgentProviderConfig> {
    return this.agentProvidersService.update(id, dto);
  }

  @Delete(":id")
  async delete(@Param("id") id: string): Promise<AgentProviderConfig> {
    return this.agentProvidersService.delete(id);
  }
}
