import type { CreatePayload, ReplacePayload, UpdatePayload } from "./__name__.payload"; export type __Pascal__Entity = { id: string; createdAt: string; updatedAt: string; } & Record; // In-memory store (replace with DB later) const db: __Pascal__Entity[] = []; function nowISO() { return new Date().toISOString(); } function newId() { return String(Date.now()) + Math.random().toString(16).slice(2); } export class __Pascal__Service { static async list() { return db; } static async getById(id: string) { return db.find(x => x.id === id) ?? null; } static async create(payload: CreatePayload) { const t = nowISO(); const item: __Pascal__Entity = { id: newId(), createdAt: t, updatedAt: t, ...payload }; db.push(item); return item; } static async replace(id: string, payload: ReplacePayload) { const idx = db.findIndex(x => x.id === id); if (idx === -1) return null; const t = nowISO(); const prev = db[idx]; const next: __Pascal__Entity = { ...prev, ...payload, id, updatedAt: t }; db[idx] = next; return next; } static async update(id: string, payload: UpdatePayload) { const idx = db.findIndex(x => x.id === id); if (idx === -1) return null; const t = nowISO(); const prev = db[idx]; const next: __Pascal__Entity = { ...prev, ...payload, id, updatedAt: t }; db[idx] = next; return next; } static async remove(id: string) { const before = db.length; const after = db.filter(x => x.id !== id); db.length = 0; db.push(...after); return after.length !== before; } }