import { base44 } from '@/api/base44Client';

/** Replaceable database contract: list, filter, get, create, update and archive records by collection. */
const collection = (name) => base44.entities[name];
export const Base44DatabaseAdapter = {
  list: (name, sort = '-updated_date', limit = 500) => collection(name).list(sort, limit),
  filter: (name, query, sort = '-updated_date', limit = 500) => collection(name).filter(query, sort, limit),
  get: (name, id) => collection(name).get(id),
  create: (name, data) => collection(name).create(data),
  update: (name, id, data) => collection(name).update(id, data),
  archive: (name, id) => collection(name).update(id, { record_state: 'archived' }),
  restore: (name, id) => collection(name).update(id, { record_state: 'active' }),
};