import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import {
  editUserActive,
  editUserMember,
  getUser,
  getUsers,
  sendEmail,
  sendNotification,
  sendSms,
} from "./controller";
import {
  emailSchema,
  notificationSchema,
  smsSchema,
  userActiveSchema,
  userMemberSchema,
} from "./schema";

export async function adminUsersRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
    },
    getUsers
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "email/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        body: emailSchema,
      },
    },
    sendEmail
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "notification/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        body: notificationSchema,
      },
    },
    sendNotification
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "sms/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        body: smsSchema,
      },
    },
    sendSms
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        params: idParamsSchema,
      },
    },
    getUser
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/active/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        params: idParamsSchema,
        body: userActiveSchema,
      },
    },
    editUserActive
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/member/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Users"),
      schema: {
        params: idParamsSchema,
        body: userMemberSchema,
      },
    },
    editUserMember
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("users routes registered");
}
