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

// The fixed set of meeting-summary lifecycle statuses. Row ids are assigned by
// the migration; this seed only makes sure the rows exist (idempotent upsert by
// the unique `code`) so a fresh `prisma migrate reset` + seed stays correct.
const MEETING_SUMMARY_STATUSES: { code: string; name: string }[] = [
  { code: 'DRAFT', name: 'Draft' },
  { code: 'REVIEWED', name: 'Reviewed' },
  { code: 'SUBMITTED', name: 'Submitted' },
  { code: 'COMPLETED', name: 'Completed' },
];

export async function seedMeetingSummaryStatuses(prisma: PrismaClient) {
  // A lookup of status code -> id, used by other seeds (e.g. meetings) that
  // need to attach a status to the summaries they create.
  const statusIdByCode = new Map<string, number>();

  for (const status of MEETING_SUMMARY_STATUSES) {
    const row = await prisma.meetingSummaryStatus.upsert({
      where: { code: status.code },
      update: { name: status.name },
      create: { code: status.code, name: status.name },
      select: { id: true, code: true },
    });

    statusIdByCode.set(row.code, row.id);
  }

  return {
    statusIdByCode,
    statusCodes: MEETING_SUMMARY_STATUSES.map((status) => status.code),
  };
}
