import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import { minioDocumentSchema } from "../minio/schema";
import {
  createTraining,
  deleteTraining,
  editTraining,
  getTraining,
  getTrainings,
  uploadTrainingDocument,
} from "./controller";
import { trainingSchema } from "./schema";

export async function adminTrainingsRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
    },
    getTrainings
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
      schema: {
        params: idParamsSchema,
      },
    },
    getTraining
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "upload-document/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
      schema: {
        body: minioDocumentSchema,
      },
    },
    uploadTrainingDocument
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
      schema: {
        body: trainingSchema,
      },
    },
    createTraining
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
      schema: {
        params: idParamsSchema,
        body: trainingSchema,
      },
    },
    editTraining
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Trainings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteTraining
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("trainings routes registered");
}
