"use server";

import { prisma } from "@/lib/prisma";

export async function getClients() {
  try {
    const clients = await prisma.user.findMany({
      where: {
        role: { not: "ADMIN" },
        OR: [
          { businesses: null },
          { businesses: { isActive: false } }
        ]
      },
      include: {
        businesses: true
      },
      orderBy: {
        createdAt: "desc"
      }
    });
    return { success: true, data: clients };
  } catch (error) {
    console.error("Failed to fetch clients:", error);
    return { success: false, error: "Erreur lors de la récupération des clients" };
  }
}
