"use server"

import { prisma } from '@/lib/prisma'

export const addSubscription = async ({ name, email }: { name: string, email: string }) => {
    await prisma?.admin_newsletter.create({ data: { name: name, email: email, isUser: false } })
}

export const getFavorites = async ({ userId }: { userId: string }) => {
    const data = await prisma?.user.findFirst({ where: { id: userId } })
    return data?.FavoriteExpertIds;
}

export const getFavoritesProfiles = async ({ userId }: { userId: string }) => {
    const data = await prisma?.user.findFirst({ where: { id: userId } })
    const profiles = await prisma?.expert.findMany({ where: { id: { in: data?.FavoriteExpertIds }} , include: {User: true} })
    return profiles;
}