import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { createVideo, deleteVideo, editVideo, getVideos } from "./controller";
import { videoSchema } from "./schema";

export async function adminVideosRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Videos"),
    },
    getVideos
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Videos"),
      schema: {
        body: videoSchema,
      },
    },
    createVideo
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Videos"),
      schema: {
        params: idParamsSchema,
        body: videoSchema,
      },
    },
    editVideo
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Videos"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteVideo
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("videos routes registered");
}
