import { createTRPCRouter, adminProcedure, managerProcedure, protectedProcedure } from "../trpc.js";
import {
  EntitlementBalanceInputSchema,
  EntitlementBulkSetInputSchema,
  EntitlementGetInputSchema,
  EntitlementSetInputSchema,
  EntitlementYearSummaryDetailInputSchema,
  EntitlementYearSummaryInputSchema,
  bulkSetEntitlements,
  getEntitlement,
  getEntitlementBalance,
  getEntitlementBalanceDetail,
  getEntitlementYearSummary,
  getEntitlementYearSummaryDetail,
  setEntitlement,
} from "./entitlement-procedure-support.js";

export const entitlementRouter = createTRPCRouter({
  getBalance: protectedProcedure
    .input(EntitlementBalanceInputSchema)
    .query(({ ctx, input }) => getEntitlementBalance(ctx, input)),

  getBalanceDetail: protectedProcedure
    .input(EntitlementBalanceInputSchema)
    .query(({ ctx, input }) => getEntitlementBalanceDetail(ctx, input)),

  get: managerProcedure
    .input(EntitlementGetInputSchema)
    .query(({ ctx, input }) => getEntitlement(ctx, input)),

  set: managerProcedure
    .input(EntitlementSetInputSchema)
    .mutation(({ ctx, input }) => setEntitlement(ctx, input)),

  bulkSet: adminProcedure
    .input(EntitlementBulkSetInputSchema)
    .mutation(({ ctx, input }) => bulkSetEntitlements(ctx, input)),

  getYearSummary: managerProcedure
    .input(EntitlementYearSummaryInputSchema)
    .query(({ ctx, input }) => getEntitlementYearSummary(ctx, input)),

  getYearSummaryDetail: managerProcedure
    .input(EntitlementYearSummaryDetailInputSchema)
    .query(({ ctx, input }) => getEntitlementYearSummaryDetail(ctx, input)),
});
