import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards, ParseUUIDPipe, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBearerAuth, ApiQuery } from '@nestjs/swagger'; import { ProfileSectionsService } from './profile-sections.service'; import { CreateSectionDto, UpdateSectionDto, AssignSectionDto, UpdateAssignmentDto } from './dto'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { RolesGuard } from '../auth/guards/roles.guard'; import { Roles } from '../auth/decorators/roles.decorator'; import { UserRole } from '@prisma/client'; @ApiTags('Profile Sections') @Controller('profile-sections') export class ProfileSectionsController { constructor(private readonly sectionsService: ProfileSectionsService) {} @Post() @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Create a new profile section (Admin only)' }) create(@Body() createSectionDto: CreateSectionDto) { return this.sectionsService.create(createSectionDto); } @Get() @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Get all profile sections (Admin only)' }) @ApiQuery({ name: 'includeInactive', required: false, type: Boolean }) findAll(@Query('includeInactive') includeInactive?: string) { return this.sectionsService.findAll(includeInactive === 'true'); } @Get(':id') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Get a profile section by ID with fields (Admin only)' }) findOne(@Param('id', ParseUUIDPipe) id: string) { return this.sectionsService.findOne(id); } @Patch(':id') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Update a profile section (Admin only)' }) update( @Param('id', ParseUUIDPipe) id: string, @Body() updateSectionDto: UpdateSectionDto, ) { return this.sectionsService.update(id, updateSectionDto); } @Delete(':id') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Delete a profile section (Admin only)' }) remove(@Param('id', ParseUUIDPipe) id: string) { return this.sectionsService.remove(id); } @Post(':id/assign') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Assign section to an agent type (Admin only)' }) assignToAgentType( @Param('id', ParseUUIDPipe) id: string, @Body() assignDto: AssignSectionDto, ) { return this.sectionsService.assignToAgentType(id, assignDto); } @Patch(':id/assignment/:agentTypeId') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Update section assignment (Admin only)' }) updateAssignment( @Param('id', ParseUUIDPipe) id: string, @Param('agentTypeId', ParseUUIDPipe) agentTypeId: string, @Body() updateDto: UpdateAssignmentDto, ) { return this.sectionsService.updateAssignment(id, agentTypeId, updateDto); } @Delete(':id/assignment/:agentTypeId') @UseGuards(JwtAuthGuard, RolesGuard) @Roles(UserRole.ADMIN) @ApiBearerAuth() @ApiOperation({ summary: 'Remove section from an agent type (Admin only)' }) removeFromAgentType( @Param('id', ParseUUIDPipe) id: string, @Param('agentTypeId', ParseUUIDPipe) agentTypeId: string, ) { return this.sectionsService.removeFromAgentType(id, agentTypeId); } }