import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { minioImageSchema } from "../minio/schema";
import {
  createAppointment,
  deleteAppointment,
  editAppointment,
  editAppointmentActive,
  getAppointment,
  getAppointments,
  uploadAppointmentImage,
} from "./controller";
import { appointmentActiveSchema, appointmentSchema } from "./schema";

export async function adminAppointmentsRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
    },
    getAppointments
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        params: idParamsSchema,
      },
    },
    getAppointment
  );

  //-------------------------------------------------------------------------------
  fastify.post(
    "upload-image/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        body: minioImageSchema,
      },
    },
    uploadAppointmentImage
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        body: appointmentSchema,
      },
    },
    createAppointment
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        params: idParamsSchema,
        body: appointmentSchema,
      },
    },
    editAppointment
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/active/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        params: idParamsSchema,
        body: appointmentActiveSchema,
      },
    },
    editAppointmentActive
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Appointments"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteAppointment
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("appointments routes registered");
}
