import { api } from '@/lib/api' import type { PriceListResponse, PriceResolution, SchemeResponse, SchemeRuleType, } 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}`), }