import { ICustomer, EntityType } from '../types/CalendarTypes'; import { IApiRepository } from './IApiRepository'; interface RawCustomerData { id: string; name: string; phone: string; email?: string; metadata?: Record; [key: string]: unknown; } /** * MockCustomerRepository - Loads customer data from local JSON file */ export class MockCustomerRepository implements IApiRepository { public readonly entityType: EntityType = 'Customer'; private readonly dataUrl = 'data/mock-customers.json'; public async fetchAll(): Promise { try { const response = await fetch(this.dataUrl); if (!response.ok) { throw new Error(`Failed to load mock customers: ${response.status} ${response.statusText}`); } const rawData: RawCustomerData[] = await response.json(); return this.processCustomerData(rawData); } catch (error) { console.error('Failed to load customer data:', error); throw error; } } public async sendCreate(_customer: ICustomer): Promise { throw new Error('MockCustomerRepository does not support sendCreate. Mock data is read-only.'); } public async sendUpdate(_id: string, _updates: Partial): Promise { throw new Error('MockCustomerRepository does not support sendUpdate. Mock data is read-only.'); } public async sendDelete(_id: string): Promise { throw new Error('MockCustomerRepository does not support sendDelete. Mock data is read-only.'); } private processCustomerData(data: RawCustomerData[]): ICustomer[] { return data.map((customer): ICustomer => ({ id: customer.id, name: customer.name, phone: customer.phone, email: customer.email, metadata: customer.metadata, syncStatus: 'synced' as const })); } }