'use server'
import { prisma } from "@/module/_global";

export default async function funGetUserById({ id }: { id: string }) {
   const user = await prisma.user.findUnique({
      where: {
         id: id
      },
   });

   if (!user) {
      return {
         id: undefined,
         idUserRole: undefined,
         name: undefined,
         idVillage: undefined,
         idGroup: undefined,
         idPosition: undefined,
         theme: undefined,
      }
   }

   const village = await prisma.village.findUnique({
      where: {
         id: user.idVillage
      }
   })

   const warna = await prisma.colorTheme.findUnique({
      where: {
         id: String(village?.idTheme)
      }
   })

   return {
      id: user?.id,
      idUserRole: user?.idUserRole,
      name: user?.name,
      idVillage: user?.idVillage,
      idGroup: user?.idGroup,
      idPosition: user?.idPosition,
      theme: warna,
   }

}