import api from './api'; import type { Product, ProductBundleComponent } from '../types/Product'; export const productService = { getAll: async (): Promise => { const response = await api.get('/products'); return response.data; }, getById: async (id: number): Promise => { const response = await api.get(`/products/${id}`); return response.data; }, create: async (product: Partial): Promise => { const response = await api.post('/products', product); return response.data; }, update: async (id: number, product: Partial): Promise => { await api.put(`/products/${id}`, product); }, // --- GESTIÓN DE COMBOS (BUNDLES) --- /** * Agrega un producto hijo a un combo padre. */ addComponentToBundle: async (bundleId: number, component: { childProductId: number; quantity: number; fixedAllocationAmount?: number }) => { await api.post(`/products/${bundleId}/components`, component); }, /** * Elimina un componente de un combo. */ removeComponentFromBundle: async (bundleId: number, childProductId: number) => { // Nota: El backend espera el ID del producto hijo, no el ID de la relación, // según nuestra implementación de 'RemoveComponentFromBundleAsync' en el repo. await api.delete(`/products/${bundleId}/components/${childProductId}`); }, /** * Obtiene la lista de componentes que forman un combo. */ getBundleComponents: async (bundleId: number): Promise => { const response = await api.get(`/products/${bundleId}/components`); return response.data; } };