"use server";

import { categorySchema } from "@/lib/validation/zod/category";
import { api } from "@/trpc/server";
import { revalidatePath } from "next/cache";
import { z } from "zod";

export async function createCategory(category: z.infer<typeof categorySchema>) {
  const result = await api.category.create({
    category,
  });
  if (!result[0]?.slug?.length) return false;
  return revalidatePath("/");
}
export async function updateCategory(
  category: z.infer<typeof categorySchema>,
  categoryId: string,
) {
  try {
    const result = await api.category.update({
      category,
      categoryId,
    });

    if (!result[0]?.id?.length) return false;
    revalidatePath(`/artikel/${result[0].id}/edit`);
    return true;
  } catch (e) {
    console.error(e);
    return false;
  }
}
export async function deleteCategory(categoryId: string) {
  const result = await api.category.delete({
    categoryId,
  });
}
