import { z } from "zod/v4";
import {
	adminProcedure,
	createTRPCRouter,
	publicProcedure,
} from "~/server/api/trpc";
import {
	AddFlagHandler,
	EditFlagHandler,
	GetFlagHandler,
	GetFlagValueHandler,
	RemoveFlagHandler,
} from "~/server/controllers/flags.controller";
import { db } from "~/server/db";
import { zFlagsId } from "~/server/utils/zod_types";

export const flagsRouter = createTRPCRouter({
	AddFlag: adminProcedure
		.input(
			z.object({
				id: zFlagsId,
				value: z.boolean(),
			}),
		)
		.mutation(async ({ input }) => {
			return await AddFlagHandler({ db, input });
		}),
	EditFlag: adminProcedure
		.input(
			z.object({
				id: zFlagsId,
				value: z.boolean(),
			}),
		)
		.mutation(async ({ input }) => {
			return await EditFlagHandler({ db, input });
		}),

	GetFlags: adminProcedure.query(async () => {
		return await GetFlagHandler({ db });
	}),

	GetFlagValue: publicProcedure
		.input(z.object({ id: z.string() }))
		.query(async ({ input }) => {
			return await GetFlagValueHandler({ db, id: input.id });
		}),
	RemoveFlag: adminProcedure

		.input(
			z.object({
				id: zFlagsId,
			}),
		)
		.mutation(async ({ input }) => {
			return await RemoveFlagHandler({ db, id: input.id });
		}),
});
