import { z } from "zod/v4";
import { adminProcedure, createTRPCRouter } from "~/server/api/trpc";
import { db } from "~/server/db";
import {
	addBan,
	getBanList,
	removeBan,
	updateBan,
} from "~/server/services/banlist.service";
import { zBanlistId, zBanType } from "~/server/utils/zod_types";

export const banlistRouter = createTRPCRouter({
	addBan: adminProcedure
		.input(
			z.object({
				type: zBanType,
				value: z.string(),
			}),
		)
		.mutation(async ({ input }) => {
			return await addBan({
				db,
				type: input.type,
				value: input.value,
			});
		}),
	getBanlist: adminProcedure.query(async () => {
		return await getBanList({ db });
	}),
	removeBan: adminProcedure
		.input(
			z.object({
				id: zBanlistId,
			}),
		)
		.mutation(async ({ input }) => {
			return await removeBan({
				db,
				id: input.id,
			});
		}),
	updateBan: adminProcedure
		.input(
			z.object({
				id: zBanlistId,
				type: zBanType,
				value: z.string(),
			}),
		)
		.mutation(async ({ input }) => {
			return await updateBan({
				db,
				id: input.id,
				type: input.type,
				value: input.value,
			});
		}),
});
