import { MeetingStatus } from '@/generated/prisma/client';

// Old UI values are accepted while the application moves to enum values.
export function normalizeMeetingStatus(value: unknown): unknown {
  if (typeof value !== 'string') {
    return value;
  }

  const status = value.trim().toUpperCase();

  if (status === 'DRAFT' || status === 'DRAFTED') {
    return MeetingStatus.DRAFT;
  }

  if (status === 'SCHEDULED' || status === 'SCHEDULE') {
    return MeetingStatus.SCHEDULED;
  }

  if (status === 'SUBMITTED') {
    return MeetingStatus.SUBMITTED;
  }

  if (status === 'COMPLETED') {
    return MeetingStatus.COMPLETED;
  }

  // Keep invalid values so @IsEnum can return a clear validation error.
  return value;
}
