import { projectCostReadProcedures } from "./project-cost-read.js";
import { projectCoverProcedures } from "./project-cover.js";
import { projectIdentifierReadProcedures } from "./project-identifier-read.js";
import { createProjectLifecycleProcedures } from "./project-lifecycle.js";
import { createProjectMutationProcedures } from "./project-mutations.js";
import { createProjectBackgroundEffects } from "./project-background-effects.js";
import {
  getProjectById,
  getProjectShoringRatioData,
  listProjects,
  ProjectIdInputSchema,
  ProjectListInputSchema,
  ProjectShoringRatioInputSchema,
} from "./project-procedure-support.js";
import { controllerProcedure, createTRPCRouter } from "../trpc.js";

const projectBackgroundEffects = createProjectBackgroundEffects();

export const projectRouter = createTRPCRouter({
  ...projectCostReadProcedures,
  ...projectCoverProcedures,
  ...projectIdentifierReadProcedures,
  ...createProjectLifecycleProcedures({
    invalidateDashboardCacheInBackground: projectBackgroundEffects.invalidateDashboardCacheInBackground,
    dispatchProjectWebhookInBackground: projectBackgroundEffects.dispatchProjectWebhookInBackground,
  }),
  ...createProjectMutationProcedures(projectBackgroundEffects),

  list: controllerProcedure
    .input(ProjectListInputSchema)
    .query(({ ctx, input }) => listProjects(ctx, input)),

  getById: controllerProcedure
    .input(ProjectIdInputSchema)
    .query(({ ctx, input }) => getProjectById(ctx, input)),

  getShoringRatio: controllerProcedure
    .input(ProjectShoringRatioInputSchema)
    .query(({ ctx, input }) => getProjectShoringRatioData(ctx, input)),

});
