import { Body, Controller, Get, Param, Patch, Post, Query, UseGuards } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiResponse, ApiBody } from '@nestjs/swagger'; import { FleetService } from './fleet.service'; import { CreateTrainServiceDto, CreateCoachDto, CreateSeatBatchDto, UpdateCoachDto } from './fleet.dto'; import { JwtGuard } from '../../common/jwt.guard'; @ApiTags('Fleet') @Controller('fleet') @UseGuards(JwtGuard) @ApiBearerAuth('JWT-auth') export class FleetController { constructor(private service: FleetService) {} @Get('services') @ApiOperation({ summary: 'List train services' }) @ApiResponse({ status: 200, description: 'Returns all train services with recent trips' }) getServices() { return this.service.getServices(); } @Post('services') @ApiOperation({ summary: 'Create a train service' }) @ApiBody({ type: CreateTrainServiceDto }) @ApiResponse({ status: 201, description: 'Train service created' }) createService(@Body() dto: CreateTrainServiceDto) { return this.service.createService(dto); } @Get('coaches') @ApiOperation({ summary: 'List coaches' }) @ApiQuery({ name: 'tripId', required: false, description: 'Filter by trip UUID' }) @ApiResponse({ status: 200, description: 'Returns coaches with seat class and seat count' }) listCoaches(@Query('tripId') tripId?: string) { return this.service.listCoaches(tripId); } @Post('coaches') @ApiOperation({ summary: 'Add a coach to a trip' }) @ApiBody({ type: CreateCoachDto }) @ApiResponse({ status: 201, description: 'Coach created' }) createCoach(@Body() dto: CreateCoachDto) { return this.service.createCoach(dto); } @Patch('coaches/:id') @ApiOperation({ summary: 'Update a coach' }) @ApiParam({ name: 'id', description: 'Coach UUID' }) @ApiBody({ type: UpdateCoachDto }) @ApiResponse({ status: 200, description: 'Coach updated' }) @ApiResponse({ status: 404, description: 'Coach not found' }) updateCoach(@Param('id') id: string, @Body() dto: UpdateCoachDto) { return this.service.updateCoach(id, dto); } @Post('seats/batch') @ApiOperation({ summary: 'Batch-create seats for a coach' }) @ApiBody({ type: CreateSeatBatchDto }) @ApiResponse({ status: 201, description: 'Seats created' }) @ApiResponse({ status: 404, description: 'Coach not found' }) createSeatBatch(@Body() dto: CreateSeatBatchDto) { return this.service.createSeatBatch(dto); } @Get('analytics') @ApiOperation({ summary: 'Fleet analytics' }) @ApiResponse({ status: 200, description: 'Returns fleet occupancy analytics' }) getAnalytics() { return this.service.getAnalytics(); } }