import {
  CreateManagementLevelGroupSchema,
  CreateManagementLevelSchema,
} from "@capakraken/shared";
import { adminProcedure, createTRPCRouter, planningReadProcedure } from "../trpc.js";
import {
  createManagementLevel,
  createManagementLevelGroup,
  deleteManagementLevel,
  getManagementLevelGroupById,
  listManagementLevelGroups,
  managementLevelGroupIdInputSchema,
  managementLevelGroupUpdateInputSchema,
  managementLevelIdInputSchema,
  managementLevelUpdateInputSchema,
  updateManagementLevel,
  updateManagementLevelGroup,
} from "./management-level-procedure-support.js";

export const managementLevelRouter = createTRPCRouter({
  // ─── Groups ─────────────────────────────────────────────

  listGroups: planningReadProcedure.query(({ ctx }) => listManagementLevelGroups(ctx)),

  getGroupById: planningReadProcedure
    .input(managementLevelGroupIdInputSchema)
    .query(({ ctx, input }) => getManagementLevelGroupById(ctx, input)),

  createGroup: adminProcedure
    .input(CreateManagementLevelGroupSchema)
    .mutation(({ ctx, input }) => createManagementLevelGroup(ctx, input)),

  updateGroup: adminProcedure
    .input(managementLevelGroupUpdateInputSchema)
    .mutation(({ ctx, input }) => updateManagementLevelGroup(ctx, input)),

  // ─── Levels ─────────────────────────────────────────────

  createLevel: adminProcedure
    .input(CreateManagementLevelSchema)
    .mutation(({ ctx, input }) => createManagementLevel(ctx, input)),

  updateLevel: adminProcedure
    .input(managementLevelUpdateInputSchema)
    .mutation(({ ctx, input }) => updateManagementLevel(ctx, input)),

  deleteLevel: adminProcedure
    .input(managementLevelIdInputSchema)
    .mutation(({ ctx, input }) => deleteManagementLevel(ctx, input)),
});
