import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import {
  appointmentComment,
  appointmentLike,
  getAppointment,
  getAppointments,
  appointmentRegister,
} from "./controller";
import { appointmentCommentSchema } from "./schema";

export async function appointmentsRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
    },
    getAppointments
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    getAppointment
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    ":id/like/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    appointmentLike
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    ":id/comment/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
        body: appointmentCommentSchema,
      },
    },
    appointmentComment
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    ":id/register/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    appointmentRegister
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("appointments routes registered");
}
