import { Controller, Get, Param, Query, Post, Body, UseGuards } from '@nestjs/common';
import { DoctorProfileService } from './doctor_profile.service';
import { DoctorProfile } from './entities/doctor_profile.entity';
import { AuthGuard } from 'src/auth/auth.guard';
import { SkipThrottle, ThrottlerGuard } from '@nestjs/throttler';

@Controller('doctor_profile')
export class DoctorProfileController {
  constructor(private readonly doctorProfileService: DoctorProfileService) { }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @Post()
  create(@Body() StaffReview: DoctorProfile) {
    return this.doctorProfileService.create(StaffReview);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.doctorProfileService.findOne(+id);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('/about/:id')
  findAbout(@Param('id') id: number) {
    return this.doctorProfileService.findAbout(+id);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('/calender/:id')
  findshift(@Param('id') id: number, @Query('date') date: string) {
    return this.doctorProfileService.findCalender(+id, date);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('/docHos/:id')
  findhos(@Param('id') id: number) {
    return this.doctorProfileService.finddocHos(+id);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('/stats/:id')
  findstats(@Param('id') id: number) {
    return this.doctorProfileService.findDocRating(+id);
  }
  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('/review/:id')
  findreview(@Param('id') id: number) {
    return this.doctorProfileService.findDocReview(+id);
  }

  @UseGuards(AuthGuard, ThrottlerGuard)
  @SkipThrottle()
  @Get('v2/review/:id')
  async findreviewlist(@Param('id') id: number, @Query('limit') limit?: string,
    @Query('page') page?: string) {
    try {
      let doc_res = await this.doctorProfileService.findDocReviewlist(+id, +limit || 10, +page || 1);
      if (doc_res.details.length > 0) {
        return {
          status_code: process.env.SUCCESS_STATUS_CODE,
          status: process.env.SUCCESS_STATUS,
          message: process.env.SUCCESS_MESSAGE,
          data: doc_res.details,
          total: doc_res.total,
        };
      }
      else {
        return {
          status_code: process.env.SUCCESS_STATUS_CODE,
          status: process.env.SUCCESS_STATUS,
          message: process.env.DATA_NOT_FOUND
        }
      }
    } catch (error) {
      return {
        status_code: process.env.ERROR_STATUS_CODE,
        status: process.env.ERROR_STATUS,
        message: process.env.ERROR_MESSAGE
      }
    }
  }
}
