import { ICalendarEvent } from '../types/CalendarTypes'; import { IEventRepository, UpdateSource } from './IEventRepository'; interface RawEventData { id: string; title: string; start: string | Date; end: string | Date; type: string; color?: string; allDay?: boolean; [key: string]: unknown; } /** * MockEventRepository - Loads event data from local JSON file (LEGACY) * * This repository implementation fetches mock event data from a static JSON file. * DEPRECATED: Use IndexedDBEventRepository for offline-first functionality. * * Data Source: data/mock-events.json * * NOTE: Create/Update/Delete operations are not supported - throws errors. * This is intentional to encourage migration to IndexedDBEventRepository. */ export class MockEventRepository implements IEventRepository { private readonly dataUrl = 'data/mock-events.json'; public async loadEvents(): Promise { try { const response = await fetch(this.dataUrl); if (!response.ok) { throw new Error(`Failed to load mock events: ${response.status} ${response.statusText}`); } const rawData: RawEventData[] = await response.json(); return this.processCalendarData(rawData); } catch (error) { console.error('Failed to load event data:', error); throw error; } } /** * NOT SUPPORTED - MockEventRepository is read-only * Use IndexedDBEventRepository instead */ public async createEvent(event: Omit, source?: UpdateSource): Promise { throw new Error('MockEventRepository does not support createEvent. Use IndexedDBEventRepository instead.'); } /** * NOT SUPPORTED - MockEventRepository is read-only * Use IndexedDBEventRepository instead */ public async updateEvent(id: string, updates: Partial, source?: UpdateSource): Promise { throw new Error('MockEventRepository does not support updateEvent. Use IndexedDBEventRepository instead.'); } /** * NOT SUPPORTED - MockEventRepository is read-only * Use IndexedDBEventRepository instead */ public async deleteEvent(id: string, source?: UpdateSource): Promise { throw new Error('MockEventRepository does not support deleteEvent. Use IndexedDBEventRepository instead.'); } private processCalendarData(data: RawEventData[]): ICalendarEvent[] { return data.map((event): ICalendarEvent => ({ ...event, start: new Date(event.start), end: new Date(event.end), type: event.type, allDay: event.allDay || false, syncStatus: 'synced' as const })); } }