import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { getEvents, getEvent, eventLike, eventComment } from "./controller";
import { eventCommentSchema } from "./schema";

export async function eventsRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
    },
    getEvents
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    getEvent
  );
  //-------------------------------------------------------------------------------

  fastify.post(
    ":id/like/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    eventLike
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    ":id/comment/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
        body: eventCommentSchema,
      },
    },
    eventComment
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("events routes registered");
}
