import { idParamsSchema } from "../../utils/schema";
import { FastifyInstanceType } from "../../utils/types";
import {
  turnovers,
  nEmployees,
  cities,
  positions,
  activities,
  activitiesFamilies,
  expertiseAreas,
  interestAreas,
  addCity,
  editCity,
  deleteCity,
  addActivity,
  editActivity,
  deleteActivity,
  addActivityFamily,
  editActivityFamily,
  deleteActivityFamily,
  addTurnover,
  editTurnover,
  deleteTurnover,
  addPosition,
  editPosition,
  deletePosition,
  addNEmployees,
  editNEmployees,
  deleteNEmployees,
  addExpertiseArea,
  editExpertiseArea,
  deleteExpertiseArea,
  deleteInterestArea,
  editInterestArea,
  addInterestArea,
  provinces,
  editProvince,
  addProvince,
  deleteProvince,
  categories,
  addCategory,
  editCategory,
  deleteCategory,
  editCommission,
  deleteCommission,
  addCommission,
  commissions,
  addMandate,
  mandates,
  editMandate,
  deleteMandate,
  deleteCollege,
  editCollege,
  addCollege,
  colleges,
} from "./controller";
import {
  activityFamiliySchema,
  activitySchema,
  categorySchema,
  citySchema,
  collegeSchema,
  commissionSchema,
  expertiseAreaSchema,
  interestAreaSchema,
  mandateSchema,
  nEmployeesSchema,
  positionSchema,
  provinceSchema,
  turnoverSchema,
} from "./schema";

export async function adminSettingRoutes(fastify: FastifyInstanceType) {
  //-------------------------------------------------------------------------------
  fastify.get(
    "cities/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    cities
  );

  fastify.post(
    "cities/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: citySchema,
      },
    },
    addCity
  );

  fastify.put(
    "cities/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: citySchema,
      },
    },
    editCity
  );

  fastify.delete(
    "cities/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteCity
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "activities-families/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    activitiesFamilies
  );
  fastify.post(
    "activities-families/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: activityFamiliySchema,
      },
    },
    addActivityFamily
  );
  fastify.put(
    "activities-families/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: activityFamiliySchema,
      },
    },
    editActivityFamily
  );
  fastify.delete(
    "activities-families/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteActivityFamily
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "activities/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    activities
  );
  fastify.post(
    "activities/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: activitySchema,
      },
    },
    addActivity
  );
  fastify.put(
    "activities/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: activitySchema,
      },
    },
    editActivity
  );
  fastify.delete(
    "activities/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteActivity
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "turnovers/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    turnovers
  );

  fastify.post(
    "turnovers/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: turnoverSchema,
      },
    },
    addTurnover
  );

  fastify.put(
    "turnovers/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: turnoverSchema,
      },
    },
    editTurnover
  );

  fastify.delete(
    "turnovers/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteTurnover
  );

  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------

  fastify.get(
    "positions/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    positions
  );

  fastify.post(
    "positions/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: positionSchema,
      },
    },
    addPosition
  );

  fastify.put(
    "positions/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: positionSchema,
      },
    },
    editPosition
  );

  fastify.delete(
    "positions/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deletePosition
  );

  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "n-employees/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    nEmployees
  );

  fastify.post(
    "n-employees/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: nEmployeesSchema,
      },
    },
    addNEmployees
  );

  fastify.put(
    "n-employees/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: nEmployeesSchema,
      },
    },
    editNEmployees
  );

  fastify.delete(
    "n-employees/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteNEmployees
  );

  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------

  fastify.get(
    "expertise-areas/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    expertiseAreas
  );

  fastify.post(
    "expertise-areas/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: expertiseAreaSchema,
      },
    },
    addExpertiseArea
  );

  fastify.put(
    "expertise-areas/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: expertiseAreaSchema,
      },
    },
    editExpertiseArea
  );

  fastify.delete(
    "expertise-areas/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteExpertiseArea
  );

  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "interest-areas/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    interestAreas
  );

  fastify.post(
    "interest-areas/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: interestAreaSchema,
      },
    },
    addInterestArea
  );

  fastify.put(
    "interest-areas/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: interestAreaSchema,
      },
    },
    editInterestArea
  );

  fastify.delete(
    "interest-areas/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteInterestArea
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------

  fastify.get(
    "provinces/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    provinces
  );

  fastify.post(
    "provinces/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: provinceSchema,
      },
    },
    addProvince
  );

  fastify.put(
    "provinces/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: provinceSchema,
      },
    },
    editProvince
  );

  fastify.delete(
    "provinces/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteProvince
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------

  fastify.get(
    "categories/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    categories
  );

  fastify.post(
    "categories/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: categorySchema,
      },
    },
    addCategory
  );

  fastify.put(
    "categories/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: categorySchema,
      },
    },
    editCategory
  );

  fastify.delete(
    "categories/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteCategory
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "commissions/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    commissions
  );

  fastify.post(
    "commissions/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: commissionSchema,
      },
    },
    addCommission
  );

  fastify.put(
    "commissions/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: commissionSchema,
      },
    },
    editCommission
  );

  fastify.delete(
    "commissions/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteCommission
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "mandates/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    mandates
  );

  fastify.post(
    "mandates/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: mandateSchema,
      },
    },
    addMandate
  );

  fastify.put(
    "mandates/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: mandateSchema,
      },
    },
    editMandate
  );

  fastify.delete(
    "mandates/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteMandate
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.get(
    "colleges/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
    },
    colleges
  );

  fastify.post(
    "colleges/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        body: collegeSchema,
      },
    },
    addCollege
  );

  fastify.put(
    "colleges/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
        body: collegeSchema,
      },
    },
    editCollege
  );

  fastify.delete(
    "colleges/:id/",
    {
      preHandler: (req, reply) => fastify.adminAuth(req, reply, "Settings"),
      schema: {
        params: idParamsSchema,
      },
    },
    deleteCollege
  );
  //-------------------------------------------------------------------------------
  //-------------------------------------------------------------------------------
  fastify.log.info("settings routes registered");
}
