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

@ApiTags('Doctors')
@Controller()
export class DoctorsController {
  constructor(private doctorsService: DoctorsService) {}

  @Get('doctors')
  findAll() {
    return this.doctorsService.findAll();
  }

  @Get('doctor/:slug')
  findBySlug(@Param('slug') slug: string) {
    return this.doctorsService.findBySlug(slug);
  }

  @Get('doctor/:id/schedule')
  getSchedule(@Param('id') id: string) {
    return this.doctorsService.getSchedule(+id);
  }

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

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/doctors')
  create(@Body() data: { name: string; photo?: string; specialization?: string; education?: string; bio?: string }) {
    return this.doctorsService.create(data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Put('admin/doctors/:id')
  update(@Param('id') id: string, @Body() data: any) {
    return this.doctorsService.update(+id, data);
  }

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

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/doctors/:doctorId/poli/:poliId')
  assignPoli(@Param('doctorId') doctorId: string, @Param('poliId') poliId: string) {
    return this.doctorsService.assignPoli(+doctorId, +poliId);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Delete('admin/doctors/:doctorId/poli/:poliId')
  removePoli(@Param('doctorId') doctorId: string, @Param('poliId') poliId: string) {
    return this.doctorsService.removePoli(+doctorId, +poliId);
  }
}
