import { Controller, Get, Post, Body, Param } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiBody, ApiParam } from '@nestjs/swagger';
import { ReservationsService } from './reservations.service';
import { ReservationItemDto, ReservationWithYachtDto } from './reservation-item.dto';

@Controller('reservations')
export class ReservationsController {
  constructor(private readonly reservationsService: ReservationsService) {}

  @Post()
  @ApiOperation({ summary: 'Создать новую резервацию' })
  @ApiBody({ type: ReservationItemDto })
  @ApiResponse({ status: 201, description: 'Резервация успешно создана' })
  create(@Body() dto: ReservationItemDto) {
    return this.reservationsService.createReservation(dto);
  }

  @Get('user/:userId')
  @ApiOperation({ summary: 'Получить резервации по ID пользователя' })
  @ApiParam({ name: 'userId', description: 'ID пользователя', type: Number })
  @ApiResponse({
    status: 200,
    description: 'Список резерваций пользователя с данными о яхтах',
    type: [ReservationWithYachtDto],
  })
  async findByUserId(@Param('userId') userId: string) {
    return this.reservationsService.getReservationsByUserId(Number(userId));
  }

  @Get('yacht/:yachtId')
  findByYachtId(@Param('yachtId') yachtId: string) {
    return this.reservationsService.getReservationsByYachtId(Number(yachtId));
  }

  @Get()
  findAll() {
    return this.reservationsService.getAllReservations();
  }
}
