import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { minioImageSchema } from "../minio/schema";
import {
  createEvent,
  deleteEvent,
  editEvent,
  editEventActive,
  getEvent,
  getEvents,
  uploadEventImage,
} from "./controller";
import { eventActiveSchema, eventSchema } from "./schema";

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

  //-------------------------------------------------------------------------------
  fastify.post(
    "upload-image/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Events"),
      schema: {
        body: minioImageSchema,
      },
    },
    uploadEventImage
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Events"),
      schema: {
        body: eventSchema,
      },
    },
    createEvent
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Events"),
      schema: {
        params: idParamsSchema,
        body: eventSchema,
      },
    },
    editEvent
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/active/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Events"),
      schema: {
        params: idParamsSchema,
        body: eventActiveSchema,
      },
    },
    editEventActive
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Events"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteEvent
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("events routes registered");
}
