import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { minioImageSchema } from "../minio/schema";
import {
  createAlbum,
  deleteAlbum,
  editAlbum,
  getAlbum,
  getAlbums,
  uploadAlbumImage,
} from "./controller";
import { albumSchema } from "./schema";

export async function adminAlbumsRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
    },
    getAlbums
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
      schema: {
        params: idParamsSchema,
      },
    },
    getAlbum
  );

  //-------------------------------------------------------------------------------
  fastify.post(
    "upload-image/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
      schema: {
        body: minioImageSchema,
      },
    },
    uploadAlbumImage
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
      schema: {
        body: albumSchema,
      },
    },
    createAlbum
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
      schema: {
        params: idParamsSchema,
        body: albumSchema,
      },
    },
    editAlbum
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Albums"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteAlbum
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("albums routes registered");
}
