import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import {
  currentUser,
  editPassword,
  editOtherInformation,
  editPersonalInformation,
  getNotifications,
  readNotification,
} from "./controller";
import {
  notificationQueryStringSchema,
  otherInformationSchema,
  passwordSchema,
  profileSchema,
} from "./schema";

export async function profileRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
    },
    currentUser
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    "notifications/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        querystring: notificationQueryStringSchema,
      },
    },
    getNotifications
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "notifications/:id/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        params: idParamsSchema,
      },
    },
    readNotification
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "personal-information/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        body: profileSchema,
      },
    },
    editPersonalInformation
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "other-information/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        body: otherInformationSchema,
      },
    },
    editOtherInformation
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    "password/",
    {
      preHandler: (req, reply) => fastify.auth(req, reply, true),
      schema: {
        body: passwordSchema,
      },
    },
    editPassword
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("profile routes registered");
}
