import { api } from '@/lib/api' import type { PriceListResponse, PriceResolution, SchemeResponse, SchemeRuleType, SchemeSuggestion, } from '@/types/api' // ─── Price Lists ────────────────────────────────────────────────────────────── export interface PriceListItemBody { itemId: string price: number minPrice?: number | null } export interface PriceListBody { name: string regionId?: string | null effectiveFrom: string effectiveTo: string isActive?: boolean items: PriceListItemBody[] } export const priceLists = { list: (params?: { regionId?: string }) => api.get('/price-lists', { params }).then(r => r.data), get: (id: string) => api.get(`/price-lists/${id}`).then(r => r.data), create: (body: PriceListBody) => api.post('/price-lists', body).then(r => r.data), update: (id: string, body: Partial) => api.put(`/price-lists/${id}`, body).then(r => r.data), remove: (id: string) => api.delete(`/price-lists/${id}`), upsertItem: (priceListId: string, sku: string, body: { price: number; minPrice?: number | null; retailPrice?: number | null; agencyMarginPercent?: number | null }) => api.put(`/price-lists/${priceListId}/items/${encodeURIComponent(sku)}`, body).then(r => r.data), removeItem: (priceListId: string, sku: string) => api.delete(`/price-lists/${priceListId}/items/${encodeURIComponent(sku)}`).then(r => r.data), resolve: (params: { itemId: string; storeId: string; saleDate: string }) => api.get('/price-lists/resolve', { params }).then(r => r.data), } // ─── Schemes ────────────────────────────────────────────────────────────────── export interface BundleComponentBody { itemId: string qty: number } export interface SchemeBody { name: string ruleType: SchemeRuleType ruleConfig?: string | null triggerItemId?: string | null triggerQty?: number freeItemId?: string | null freeQty?: number bundleComponents?: BundleComponentBody[] regionId?: string | null eligibleSegment?: string | null dateRangeFrom: string dateRangeTo: string agentLimitExempt?: boolean baselineExpectedSales?: number isActive?: boolean } export const schemes = { list: (params?: { regionId?: string }) => api.get('/schemes', { params }).then(r => r.data), get: (id: string) => api.get(`/schemes/${id}`).then(r => r.data), create: (body: SchemeBody) => api.post('/schemes', body).then(r => r.data), update: (id: string, body: Partial) => api.put(`/schemes/${id}`, body).then(r => r.data), remove: (id: string) => api.delete(`/schemes/${id}`), setFreeGoodsRule: (id: string, body: { triggerItemId?: string | null; triggerQty?: number | null; freeItemId: string; freeQty: number }) => api.put(`/schemes/${id}/free-goods-rule`, body).then(r => r.data), upsertBundleComponent: (id: string, itemId: string, qty: number) => api.put(`/schemes/${id}/bundle-components/${itemId}`, { qty }).then(r => r.data), removeBundleComponent: (id: string, itemId: string) => api.delete(`/schemes/${id}/bundle-components/${itemId}`).then(r => r.data), /** Schemes the lines of a not-yet-saved Shop PO qualify for (or are close to). */ suggest: (body: { storeId: string; items: { itemId: string; quantity: number; unitPrice?: number | null }[] }) => api.post('/schemes/suggest', body).then(r => r.data), }