import { Controller, Get, Patch, Body, Param, Request, UseGuards } from "@nestjs/common";
import { WorkspaceSettingsService } from "./workspace-settings.service";
import { UpdateWorkspaceSettingsDto } from "./dto";
import { AuthGuard } from "../auth/guards/auth.guard";
import type { AuthenticatedRequest } from "../common/types/user.types";

/**
 * Controller for workspace LLM settings endpoints
 * All endpoints require authentication
 */
@Controller("workspaces/:workspaceId/settings/llm")
@UseGuards(AuthGuard)
export class WorkspaceSettingsController {
  constructor(private readonly workspaceSettingsService: WorkspaceSettingsService) {}

  /**
   * GET /api/workspaces/:workspaceId/settings/llm
   * Get workspace LLM settings
   */
  @Get()
  async getSettings(@Param("workspaceId") workspaceId: string) {
    return this.workspaceSettingsService.getSettings(workspaceId);
  }

  /**
   * PATCH /api/workspaces/:workspaceId/settings/llm
   * Update workspace LLM settings
   */
  @Patch()
  async updateSettings(
    @Param("workspaceId") workspaceId: string,
    @Body() dto: UpdateWorkspaceSettingsDto
  ) {
    return this.workspaceSettingsService.updateSettings(workspaceId, dto);
  }

  /**
   * GET /api/workspaces/:workspaceId/settings/llm/effective-provider
   * Get effective LLM provider for workspace
   */
  @Get("effective-provider")
  async getEffectiveProvider(
    @Param("workspaceId") workspaceId: string,
    @Request() req: AuthenticatedRequest
  ) {
    const userId = req.user?.id;
    return this.workspaceSettingsService.getEffectiveLlmProvider(workspaceId, userId);
  }

  /**
   * GET /api/workspaces/:workspaceId/settings/llm/effective-personality
   * Get effective personality for workspace
   */
  @Get("effective-personality")
  async getEffectivePersonality(@Param("workspaceId") workspaceId: string) {
    return this.workspaceSettingsService.getEffectivePersonality(workspaceId);
  }
}
