import type { PrismaClient } from '../../src/generated/prisma/client';

// Escalation targets a ministry can pick when resolving a meeting-summary
// issue. The meeting-summary service looks these up by name.
const DEFAULT_ESCALATES = ['CDC', 'CEFP'];

export async function seedEscalates(
  prisma: PrismaClient,
  ownerUserId: number | null,
) {
  if (ownerUserId) {
    for (const name of DEFAULT_ESCALATES) {
      const existing = await prisma.escalate.findFirst({
        where: { name, deletedAt: null },
        select: { id: true },
      });

      if (!existing) {
        await prisma.escalate.create({
          data: {
            name,
            // contactPersonId has no foreign key; we reuse the owner user id.
            userId: ownerUserId,
            contactPersonId: ownerUserId,
          },
        });
      }
    }
  }

  return { escalateNames: DEFAULT_ESCALATES };
}
