import { prisma } from "@/lib/db/prisma";
import { ModuleFoundationView } from "@/components/shared/module-foundation-view";

export const dynamic = "force-dynamic";

async function getCount(): Promise<number | null> {
  try {
    return await prisma.integration.count();
  } catch {
    return null;
  }
}

export default async function IntegrationsPage() {
  const count = await getCount();
  return (
    <ModuleFoundationView
      title="Enterprise Integrations"
      description="Manage modular adapters for Microsoft Entra ID / Graph API, Freshservice ITSM, and Ramco ERP."
      phaseLabel="Phase 9 — Adapters"
      schemaEntities={["Integration", "IntegrationLog", "BackgroundJob"]}
      recordCount={count}
      plannedCapabilities={[
        "Microsoft 365 / Entra ID Graph adapter (Mock first → Approved Live)",
        "Freshservice ITSM service request & ticket sync adapter",
        "Ramco ERP manual-verified & extensible future API adapter",
        "AES-256-GCM encrypted server-side credential management",
        "Connection health tests, sync timestamps & redacted payload logs",
        "Automatic exponential-backoff retry queue & failure escalation",
      ]}
    />
  );
}
