import { Reunion, ReunionStatut } from '../interfaces/reunion';
import { HIPPODROMES_MOCK } from './hippodrome.mocks';

const now = new Date();

const REUNIONS_PER_HIPPODROME = 3;
const BASE_DATE = new Date('2025-01-05T14:00:00Z');
const STATUSES: ReunionStatut[] = [
  ReunionStatut.TERMINEE,
  ReunionStatut.EN_COURS,
  ReunionStatut.PLANIFIEE,
];

const REUNION_TITLES = [
  'Grand Prix',
  'Challenge Régional',
  'Meeting de la Capitale',
  'Trophée des Champions',
  'Festival Hippique',
  'Prix du Président',
  'Coupe des Nations',
  'Gala des Courses',
  'Trophée de la Ville',
  'Coupe de l’Avenir',
  'Grand Meeting Nocturne',
  'Festival International',
];

function slugify(value: string): string {
  return value
    .normalize('NFD')
    .replace(/[\u0300-\u036f]/g, '')
    .replace(/[^a-zA-Z0-9]/g, '')
    .toUpperCase();
}

export const REUNIONS_MOCK: Reunion[] = HIPPODROMES_MOCK.flatMap((hippodrome, hipIndex) => {
  const slug = slugify(hippodrome.nom || hippodrome.ville || `HIP${hipIndex + 1}`);

  return Array.from({ length: REUNIONS_PER_HIPPODROME }).map((_, reunionOffset) => {
    const globalIndex = hipIndex * REUNIONS_PER_HIPPODROME + reunionOffset;
    const date = new Date(BASE_DATE);
    date.setDate(BASE_DATE.getDate() + globalIndex * 2);

    const title = REUNION_TITLES[globalIndex % REUNION_TITLES.length];
    const statut = STATUSES[globalIndex % STATUSES.length];

    return {
    id: crypto.randomUUID(),
      code: `${slug}-${date.getFullYear()}-${(reunionOffset + 1).toString().padStart(2, '0')}`,
      nom: `${title} de ${hippodrome.ville}`,
      date: date.toISOString().slice(0, 10),
      numero: reunionOffset + 1,
      statut,
      hippodrome,
    totalCourses: 0,
    createdAt: now.toISOString(),
    updatedAt: now.toISOString(),
    } satisfies Reunion;
  });
});
