export interface EventException {
  id?: number;
  event_id: number;
  exception_date: string; // YYYY-MM-DD
  is_skipped: boolean;
  override_title?: string;
  override_description?: string;
  override_start?: string;
  override_end?: string;
}

export async function createEventException(exception: Omit<EventException, 'id'>) {
  const res = await fetch('/api/event_exceptions', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(exception),
  });
  const data = await res.json();
  if (!res.ok || data.error) throw new Error(data.error || 'Fehler beim Erstellen der Ausnahme');
  return data;
}

export async function listEventExceptions(eventId?: number) {
  const params = new URLSearchParams();
  if (eventId) params.set('event_id', eventId.toString());
  
  const res = await fetch(`/api/event_exceptions?${params.toString()}`);
  const data = await res.json();
  if (!res.ok || data.error) throw new Error(data.error || 'Fehler beim Laden der Ausnahmen');
  return data as EventException[];
}