import { mockExposeLeads } from '../mock-data/exposeLeads' import type { ExposeLead } from '../domain/exposeLead' import { ExposeLeadStatus } from '../domain/exposeLead' import type { IExposeLeadProvider } from './IExposeLeadProvider' let store: ExposeLead[] = [...mockExposeLeads] let sequence = store.length export const MockupExposeLeadProvider: IExposeLeadProvider = { async getAll() { return [...store] }, async getById(id) { return store.find(l => l.id === id) ?? null }, async create(input) { sequence += 1 const lead: ExposeLead = { ...input, id: `lead-${String(sequence).padStart(3, '0')}`, receivedAt: input.receivedAt ?? new Date().toISOString(), status: input.status ?? ExposeLeadStatus.ACTIVE, } store = [lead, ...store] return lead }, async archive(id) { const idx = store.findIndex(l => l.id === id) if (idx === -1) throw new Error(`Lead ${id} nicht gefunden`) store[idx] = { ...store[idx], status: ExposeLeadStatus.ARCHIVED } return store[idx] }, }