import { ICustomer } from '../types/CustomerTypes'; import { 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 * * This repository implementation fetches mock customer data from a static JSON file. * Used for development and testing instead of API calls. * * Data Source: data/mock-customers.json * * NOTE: Create/Update/Delete operations are not supported - throws errors. * Only fetchAll() is implemented for loading initial mock data. */ export class MockCustomerRepository implements IApiRepository { public readonly entityType: EntityType = 'Customer'; private readonly dataUrl = 'data/mock-customers.json'; /** * Fetch all customers from mock JSON file */ 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; } } /** * NOT SUPPORTED - MockCustomerRepository is read-only */ public async sendCreate(customer: ICustomer): Promise { throw new Error('MockCustomerRepository does not support sendCreate. Mock data is read-only.'); } /** * NOT SUPPORTED - MockCustomerRepository is read-only */ public async sendUpdate(id: string, updates: Partial): Promise { throw new Error('MockCustomerRepository does not support sendUpdate. Mock data is read-only.'); } /** * NOT SUPPORTED - MockCustomerRepository 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 => ({ ...customer, syncStatus: 'synced' as const })); } }