import type { PrismaClient } from '@prisma/client';

/**
 * FK-safe full reset for DB-backed specs. TRUNCATE … CASCADE clears every kernel
 * table regardless of relation order, so specs don't each need to know the full
 * delete order (which broke once Inbox added FK references to interaction/thread/actor).
 */
export async function resetDb(prisma: PrismaClient): Promise<void> {
  await prisma.$executeRawUnsafe(
    `TRUNCATE TABLE
      "IiosRetentionPolicySnapshot","IiosComplianceHold","IiosProjectionCursor","IiosIdempotencyCommand","IiosDlqItem","IiosAuditLink",
      "IiosMeetingActionItem","IiosActionItem","IiosTranscriptSegment","IiosMeetingTranscript","IiosMeetingSummary","IiosMeetingParticipant","IiosMeeting","IiosMeetingRequest",
      "IiosCalendarSyncCursor","IiosCalendarEvent","IiosCalendarProviderAccount","IiosAvailabilityWindow",
      "IiosAiEvidenceLink","IiosAiClaim","IiosAiToolCall","IiosAiArtifact","IiosAiModelRun","IiosAiJob","IiosEmbeddingRef",
      "IiosRouteDecision","IiosRouteBinding","IiosModerationFlag",
      "IiosInboundRawEvent","IiosDeliveryAttempt","IiosOutboundCommand","IiosRateLimitBucket","IiosMediaObject",
      "IiosTicketStateHistory","IiosTicketThreadLink","IiosCallbackRequest","IiosTicket",
      "IiosSupportTeamMember","IiosSupportQueue",
      "IiosInboxItemStateHistory","IiosInboxItem","IiosUnreadCounter","IiosMessageReceipt",
      "IiosOutboxEvent","IiosProcessedEvent","IiosMessagePart","IiosInteraction",
      "IiosThreadParticipant","IiosThread","IiosActorRef","IiosSourceHandle","IiosChannel","IiosScope"
      RESTART IDENTITY CASCADE`,
  );
}
