import {
  ApplyExperienceMultipliersSchema,
  CreateExperienceMultiplierSetSchema,
  UpdateExperienceMultiplierSetSchema,
} from "@capakraken/shared";
import { createTRPCRouter, controllerProcedure, managerProcedure } from "../trpc.js";
import {
  applyExperienceMultiplierRules,
  createExperienceMultiplierSet,
  deleteExperienceMultiplierSet,
  experienceMultiplierIdInputSchema,
  experienceMultiplierPreviewInputSchema,
  getExperienceMultiplierSetById,
  listExperienceMultiplierSets,
  previewExperienceMultipliers,
  updateExperienceMultiplierSet,
} from "./experience-multiplier-procedure-support.js";

export const experienceMultiplierRouter = createTRPCRouter({
  list: controllerProcedure.query(({ ctx }) => listExperienceMultiplierSets(ctx)),

  getById: controllerProcedure
    .input(experienceMultiplierIdInputSchema)
    .query(({ ctx, input }) => getExperienceMultiplierSetById(ctx, input)),

  create: managerProcedure
    .input(CreateExperienceMultiplierSetSchema)
    .mutation(({ ctx, input }) => createExperienceMultiplierSet(ctx, input)),

  update: managerProcedure
    .input(UpdateExperienceMultiplierSetSchema)
    .mutation(({ ctx, input }) => updateExperienceMultiplierSet(ctx, input)),

  delete: managerProcedure
    .input(experienceMultiplierIdInputSchema)
    .mutation(({ ctx, input }) => deleteExperienceMultiplierSet(ctx, input)),

  /** Preview the rate adjustment without persisting */
  preview: controllerProcedure
    .input(experienceMultiplierPreviewInputSchema)
    .query(({ ctx, input }) => previewExperienceMultipliers(ctx, input)),

  /** Apply multipliers to demand lines on the working version */
  applyRules: managerProcedure
    .input(ApplyExperienceMultipliersSchema)
    .mutation(({ ctx, input }) => applyExperienceMultiplierRules(ctx, input)),
});
