import { delay } from './api';
import { mockCategories } from '@/data/mockStores';
import type { Category } from '@/types';

let categories = [...mockCategories];

export const categoriesService = {
  list: (storeId: string) =>
    delay(categories.filter((c) => c.storeId === storeId)),
  create: (category: Category) => {
    categories = [category, ...categories];
    return delay(category);
  },
  update: (id: string, patch: Partial<Category>) => {
    categories = categories.map((c) => (c.id === id ? { ...c, ...patch } : c));
    return delay(categories.find((c) => c.id === id) ?? null);
  },
  remove: (id: string) => {
    categories = categories.filter((c) => c.id !== id);
    return delay({ success: true });
  },
};
