import { CreateRoleSchema } from "@capakraken/shared";
import {
  createTRPCRouter,
  managerProcedure,
  planningReadProcedure,
  protectedProcedure,
} from "../trpc.js";
import {
  createRole,
  deactivateRole,
  deleteRole,
  getRoleById,
  getRoleByIdentifier,
  listRoles,
  ResolveRoleIdentifierInputSchema,
  resolveRoleByIdentifier,
  RoleIdentifierInputSchema,
  RoleIdInputSchema,
  RoleListInputSchema,
  UpdateRoleProcedureInputSchema,
  updateRole,
} from "./role-procedure-support.js";

export const roleRouter = createTRPCRouter({
  list: planningReadProcedure
    .input(RoleListInputSchema)
    .query(({ ctx, input }) => listRoles(ctx, input)),

  resolveByIdentifier: protectedProcedure
    .input(ResolveRoleIdentifierInputSchema)
    .query(({ ctx, input }) => resolveRoleByIdentifier(ctx, input)),

  getByIdentifier: planningReadProcedure
    .input(RoleIdentifierInputSchema)
    .query(({ ctx, input }) => getRoleByIdentifier(ctx, input)),

  getById: planningReadProcedure
    .input(RoleIdInputSchema)
    .query(({ ctx, input }) => getRoleById(ctx, input)),

  create: managerProcedure
    .input(CreateRoleSchema)
    .mutation(({ ctx, input }) => createRole(ctx, input)),

  update: managerProcedure
    .input(UpdateRoleProcedureInputSchema)
    .mutation(({ ctx, input }) => updateRole(ctx, input)),

  delete: managerProcedure
    .input(RoleIdInputSchema)
    .mutation(({ ctx, input }) => deleteRole(ctx, input)),

  deactivate: managerProcedure
    .input(RoleIdInputSchema)
    .mutation(({ ctx, input }) => deactivateRole(ctx, input)),
});
