import { createTRPCRouter, protectedProcedure } from "$lib/trpc/t";
import { z } from "zod";
import { getCKUseCases } from "./usecases";
import { pendingActionModel } from "@pkg/logic/domains/ckflow/data/entities";

export const ckflowRouter = createTRPCRouter({
	getActiveSessionsList: protectedProcedure.query(async () => {
		return getCKUseCases().getActiveSessionsList();
	}),

	getAllSessionsList: protectedProcedure
		.input(z.object({ includeDeleted: z.boolean().default(false) }))
		.query(async ({ input }) => {
			return getCKUseCases().getAllSessionsList(input.includeDeleted);
		}),

	getFlowInfo: protectedProcedure
		.input(z.object({ flowId: z.string() }))
		.query(async ({ input }) => {
			return getCKUseCases().getFlowInfo(input.flowId);
		}),

	updateSessionAction: protectedProcedure
		.input(
			z.object({
				flowId: z.string(),
				action: pendingActionModel,
			}),
		)
		.mutation(async ({ input }) => {
			return getCKUseCases().addPendingAction(input.flowId, input.action);
		}),

	deleteSession: protectedProcedure
		.input(z.object({ flowId: z.string() }))
		.mutation(async ({ input }) => {
			return getCKUseCases().cleanupFlow(input.flowId);
		}),

	softDeleteSession: protectedProcedure
		.input(z.object({ flowId: z.string() }))
		.mutation(async ({ input }) => {
			return getCKUseCases().softDeleteFlow(input.flowId);
		}),

	restoreSession: protectedProcedure
		.input(z.object({ flowId: z.string() }))
		.mutation(async ({ input }) => {
			return getCKUseCases().restoreFlow(input.flowId);
		}),
});
