import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  UseGuards,
  ParseIntPipe,
} from '@nestjs/common';
import { RoomsService } from './rooms.service';
import { JwtAuthGuard, RolesGuard } from '../auth/guards';
import { Roles } from '../auth/guards/roles.guard';
import { CreateRoomDto, UpdateRoomDto } from './dto';

@Controller('rooms')
@UseGuards(JwtAuthGuard)
export class RoomsController {
  constructor(private readonly roomsService: RoomsService) {}

  // GET /rooms - Alle Räume abrufen
  @Get()
  async findAll() {
    return this.roomsService.findAll();
  }

  // GET /rooms/:id - Einen Raum nach ID abrufen
  @Get(':id')
  async findOne(@Param('id', ParseIntPipe) id: number) {
    return this.roomsService.findOne(id);
  }

  // POST /rooms - Neuen Raum erstellen (nur Lehrer)
  @Post()
  @UseGuards(RolesGuard)
  @Roles(['Lehrer'])
  async create(@Body() createDto: CreateRoomDto) {
    return this.roomsService.create(createDto);
  }

  // PUT /rooms/:id - Raum aktualisieren (nur Lehrer)
  @Put(':id')
  @UseGuards(RolesGuard)
  @Roles(['Lehrer'])
  async update(
    @Param('id', ParseIntPipe) id: number,
    @Body() updateDto: UpdateRoomDto,
  ) {
    return this.roomsService.update(id, updateDto);
  }

  // DELETE /rooms/:id - Raum löschen (nur Lehrer)
  @Delete(':id')
  @UseGuards(RolesGuard)
  @Roles(['Lehrer'])
  async delete(@Param('id', ParseIntPipe) id: number) {
    return this.roomsService.delete(id);
  }
}
