import { requireAccount } from "@/lib/auth";
import { prisma } from "@/lib/db";
import { AutomationsClient } from "@/components/automations/automations-client";

export const dynamic = "force-dynamic";

export default async function AutomationsPage() {
  const membership = await requireAccount();
  const accountId = membership.account.id;

  const automations = await prisma.automation.findMany({
    where: { accountId },
    orderBy: { createdAt: "desc" },
    include: {
      _count: {
        select: { steps: true, logs: true },
      },
    },
  });

  return (
    <AutomationsClient automations={automations} />
  );
}
