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

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