import { Controller, Get, Query, UseGuards } from "@nestjs/common";
import { DoctorsService } from "./doctors.service";
import {
  ApiOperation,
  ApiProperty,
  ApiQuery,
  ApiResponse,
  ApiTags,
} from "@nestjs/swagger";
import { ErrorResponse500 } from "src/appointment_status/appointment_status.controller";
import { ErrorResponse400 } from "src/appointment/entities/appointment.entity";
import { AuthGuard } from "src/auth/auth.guard";

export class DoctorDto {
  @ApiProperty({
    example: "Dr. Matheshwari N",
    description: "Name of the doctor",
  })
  doctor_name: string;

  @ApiProperty({
    example: "matheswari@plenome.com",
    description: "Email of the doctor",
  })
  email: string;

  @ApiProperty({ example: 98, description: "ID of the doctor" })
  doctor_id: number;

  @ApiProperty({ example: "Male", description: "Gender of the doctor" })
  gender: string;

  @ApiProperty({
    example: "Screenshot from 2024-02-07 12-14-29.png_1709713145092",
    description: "Image filename of the doctor",
  })
  image: string;

  @ApiProperty({ example: "MBBS", description: "Qualification of the doctor" })
  qualification: string;

  @ApiProperty({ example: "10", description: "Years of experience" })
  experience: string;

  @ApiProperty({ example: "4", description: "Rating of the doctor" })
  rating: string;

  @ApiProperty({
    example: "cardiologist",
    description: "Specialization of the doctor",
  })
  specialist_names: string;

  @ApiProperty({
    example: 100,
    description: "Standard charge for the doctor consultation",
  })
  standard_charge: number;

  @ApiProperty({
    example: "Plenome Hospital",
    description: "Name of the hospital where the doctor practices",
  })
  hospital_name: string;

  @ApiProperty({
    example: "09:00:00 - 10:00:00",
    description: "Hospital opening timings",
  })
  hospital_opening_timing: string;

  @ApiProperty({
    example: 13,
    description: "Charge ID associated with the doctor",
  })
  charge_id: number;

  @ApiProperty({
    example: "10.00%",
    description: "Tax percentage applicable to the charge",
  })
  tax_percentage: string;

  @ApiProperty({ example: 10, description: "Calculated tax amount" })
  tax: number;

  @ApiProperty({ example: 110, description: "Total amount to be paid" })
  Totalamount: number;
}

@ApiTags("doctors-list")
@Controller("doctors")
export class DoctorsController {
  constructor(private readonly doctorsService: DoctorsService) { }

  @Get()
  @Get()
  @ApiOperation({ summary: "Retrieve list of doctors based on filters" })
  @ApiQuery({
    name: "search",
    required: false,
    description: "Search term to filter doctors by name or email",
  })
  @ApiQuery({
    name: "hospital_id",
    required: true,
    description: "Hospital ID to filter doctors",
  })
  @ApiQuery({
    name: "date",
    required: false,
    description: "Date to filter doctors based on availability",
  })
  @ApiQuery({
    name: "gender",
    required: false,
    description: "Gender to filter doctors",
  })
  @ApiQuery({
    name: "specialist",
    required: false,
    description: "specialist to filter doctors",
  })
  @ApiResponse({
    status: 200,
    description: "List of doctors retrieved successfully.",
    type: [DoctorDto],
  })
  @ApiResponse({
    status: 500,
    description: "Internal server error",
    type: ErrorResponse500,
  })
  @ApiResponse({
    status: 400,
    description: "Internal server error",
    type: ErrorResponse400,
  })
  findAll(
    @Query("search") search: string,
    @Query("hospital_id") hospital_id: number,
    @Query("date") date: any,
    @Query("gender") gender: string,
    @Query("specialist_id") specialist_id: string
  ) {
    return this.doctorsService.findAll(
      search,
      hospital_id,
      date,
      gender,
      specialist_id
    );
  }

  @UseGuards(AuthGuard)
  @Get("/v2")
  @ApiOperation({ summary: "Retrieve list of doctors based on filters" })
  @ApiQuery({
    name: "search",
    required: false,
    description: "Search term to filter doctors by name or email",
  })
  @ApiQuery({
    name: "hospital_id",
    required: true,
    description: "Hospital ID to filter doctors",
  })
  @ApiQuery({
    name: "date",
    required: false,
    description: "Date to filter doctors based on availability",
  })
  @ApiQuery({
    name: "gender",
    required: false,
    description: "Gender to filter doctors",
  })
  @ApiQuery({
    name: "staff_id",
    required: false,
    description: "Staff ID to filter doctors",
  })
  @ApiResponse({
    status: 200,
    description: "List of doctors retrieved successfully.",
    type: [DoctorDto],
  })
  @ApiResponse({
    status: 500,
    description: "Internal server error",
    type: ErrorResponse500,
  })
  @ApiResponse({
    status: 400,
    description: "Internal server error",
    type: ErrorResponse400,
  })
  v2findAll(
    @Query("search") search: string,
    @Query("hospital_id") hospital_id: number,
    @Query("date") date: any,
    @Query("gender") gender: string,
    @Query("limit") limit: number,
    @Query("page") page: number,
    @Query("staff_id") staff_id: number

  ) {
    return this.doctorsService.V2findAll(
      search,
      hospital_id,
      date,
      gender,
      limit || 10,
      page || 1,
      staff_id
    );
  }

  // @UseGuards(AuthGuard)
  @Get("/getDocName")
  @ApiOperation({ summary: "Retrieve list of doctors based on filters" })
  @ApiQuery({
    name: "search",
    required: false,
    description: "Search term to filter doctors by name or email",
  })
  @ApiQuery({
    name: "hospital_id",
    required: true,
    description: "Hospital ID to filter doctors",
  })
  @ApiQuery({
    name: "date",
    required: false,
    description: "Date to filter doctors based on availability",
  })
  @ApiQuery({
    name: "gender",
    required: false,
    description: "Gender to filter doctors",
  })
  @ApiResponse({
    status: 200,
    description: "List of doctors retrieved successfully.",
    type: [DoctorDto],
  })
  @ApiResponse({
    status: 500,
    description: "Internal server error",
    type: ErrorResponse500,
  })
  @ApiResponse({
    status: 400,
    description: "Internal server error",
    type: ErrorResponse400,
  })
  findAlldoctors(
    @Query("hospital_id") hospital_id: number,
    @Query("limit") limit: number,
    @Query("page") page: number
  ) {
    if (!hospital_id) {
      return {
        status: "failed",
        message: "Enter hospital_id to get the values",
      };
    }
    return this.doctorsService.findalldoctors(
      hospital_id,
      limit || 10,
      page || 1
    );
  }
}
