import { Controller, Get, Post, Put, Delete, Body, Param, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { ScheduleService } from './schedule.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';

@ApiTags('Schedules')
@Controller()
export class ScheduleController {
  constructor(private scheduleService: ScheduleService) {}

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Get('admin/schedules')
  adminFindAll() {
    return this.scheduleService.findAll();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/schedules')
  create(@Body() data: { doctorId: number; poliId: number; day: string; startTime: string; endTime: string; room?: string }) {
    return this.scheduleService.create(data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Put('admin/schedules/:id')
  update(@Param('id') id: string, @Body() data: { day?: string; startTime?: string; endTime?: string; room?: string }) {
    return this.scheduleService.update(+id, data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Delete('admin/schedules/:id')
  remove(@Param('id') id: string) {
    return this.scheduleService.remove(+id);
  }
}
