import { PrismaService } from "../../src/prisma/prisma.service";

const TABLES = [
  "audit_log",
  "merchant_invoice_item",
  "merchant_invoice",
  "merchant_pricing_plan",
  "webhook_event_in",
  "webhook_event_out",
  "webhook_endpoint",
  "checkout_session",
  "payment_refund",
  "payment_attempt",
  "payment_intent",
  "customer",
  "merchant_provider_config",
  "merchant_api_key",
  "merchant",
  "admin_user",
];

/**
 * Trunca todas las tablas del esquema de tests preservando estructura/migraciones.
 * Llamar en `beforeEach` para mantener tests aislados.
 */
export async function truncateAll(prisma: PrismaService): Promise<void> {
  const list = TABLES.map((t) => `"${t}"`).join(", ");
  await prisma.$executeRawUnsafe(`TRUNCATE TABLE ${list} RESTART IDENTITY CASCADE;`);
}
