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

const DEFAULT_COMMENT_TYPES = [
  'Missing document',
  'Document is not corrected',
  'Information is not corrected',
  'Other',
];

/**
 * Add the standard CDC comment types once.
 *
 * A soft-deleted record is intentionally left deleted. This avoids bringing
 * back a comment type that an administrator removed.
 */
export async function seedCommentTypes(prisma: PrismaClient) {
  const seededNames: string[] = [];

  for (const name of DEFAULT_COMMENT_TYPES) {
    const existingCommentType = await prisma.commentType.findFirst({
      where: {
        name: {
          equals: name,
          mode: 'insensitive',
        },
      },
      select: { id: true },
    });

    if (existingCommentType) {
      continue;
    }

    await prisma.commentType.create({
      data: {
        name,
        description: null,
      },
    });
    seededNames.push(name);
  }

  return {
    commentTypeNames: DEFAULT_COMMENT_TYPES,
    seededNames,
  };
}
