import { FastifyInstanceType } from "../../utils/types";
import { currentUser, editProfile, editPassword } from "./controller";
import { passwordSchema, profileSchema } from "./schema";

export async function adminProfileRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, undefined),
    },
    currentUser
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, undefined),
      schema: {
        body: profileSchema,
      },
    },
    editProfile
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "password/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, undefined),
      schema: {
        body: passwordSchema,
      },
    },
    editPassword
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("profile routes registered");
}
