"use server";

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

export async function updateUserProfile(profile: z.infer<typeof userSchema>) {
  const [result] = await api.users.updateProfile({ profile });
  if (!result?.id) return { success: false };
  revalidatePath("/me");
  return { success: true };
}

export async function setUserPermissions(userId: string, permission: number) {
  const result = await api.users.setPermission({ userId, permission });
  if (!result[0]?.id) return { success: false };
  revalidatePath("/admin/benutzer");
  return { success: true };
}
