import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import {
  createElectedMember,
  deleteElectedMember,
  editElectedMember,
  getElectedMember,
  getElectedMembers,
  sendEmail,
  editElectedMemebrActive,
  editElectedMemberPassword,
  sendNotification,
  sendSms,
} from "./controller";
import {
  editElectedMemberPasswordSchema,
  editElectedMemberSchema,
  electedMemberSchema,
  electedMemebrActiveSchema,
  emailSchema,
  notificationSchema,
  smsSchema,
} from "./schema";

export async function adminElectedMembersRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
    },
    getElectedMembers
  );
  //-------------------------------------------------------------------------------
  fastify.get(
    ":id/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        params: idParamsSchema,
      },
    },
    getElectedMember
  );

  //-------------------------------------------------------------------------------
  // fastify.post(
  //   "upload-image/",
  //   {
  //     preHandler: (req, reply) =>
  //       fastify.adminAuth(req, reply, "ElectedMembers"),
  //     schema: {
  //       body: minioImageSchema,
  //     },
  //   },
  //   uploadElectedMemberImage
  // );
  //-------------------------------------------------------------------------------
  fastify.post(
    "",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        body: electedMemberSchema,
      },
    },
    createElectedMember
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "notification/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        body: notificationSchema,
      },
    },
    sendNotification
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "email/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        body: emailSchema,
      },
    },
    sendEmail
  );
  //-------------------------------------------------------------------------------
  fastify.post(
    "sms/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        body: smsSchema,
      },
    },
    sendSms
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        params: idParamsSchema,
        body: editElectedMemberSchema,
      },
    },
    editElectedMember
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/active/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        params: idParamsSchema,
        body: electedMemebrActiveSchema,
      },
    },
    editElectedMemebrActive
  );
  //-------------------------------------------------------------------------------
  fastify.put(
    ":id/password/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        params: idParamsSchema,
        body: editElectedMemberPasswordSchema,
      },
    },
    editElectedMemberPassword
  );
  //-------------------------------------------------------------------------------
  fastify.delete(
    ":id/",
    {
      preHandler: (req, reply) =>
        fastify.adminAuth(req, reply, "ElectedMembers"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteElectedMember
  );
  //-------------------------------------------------------------------------------
  fastify.log.info("elected members routes registered");
}
