import type { ProductAttributeDictionaryValue, ProductAttributeSchema, ProductEditorCategoryOption, ProductEditorContext, ProductEditorSnapshot, Operation, SaveProductEditorDraftRequest, SaveProductEditorDraftResponse, } from '@atlas/contracts'; import { api } from './api'; export const productEditorApi = { enter: (collectionItemId: string, platformId: string) => api.post( `/collection-items/${collectionItemId}/editor-contexts`, undefined, { headers: { 'X-Atlas-Platform-Id': platformId, 'Idempotency-Key': crypto.randomUUID(), }, } ), read: (productId: string, platformId: string) => api.get(`/products/${productId}/editor`, { headers: { 'X-Atlas-Platform-Id': platformId }, }), save: ( productId: string, platformId: string, revisions: { product: number; profile: number }, payload: SaveProductEditorDraftRequest ) => api.put(`/products/${productId}/editor-draft`, payload, { headers: { 'X-Atlas-Platform-Id': platformId, 'Idempotency-Key': crypto.randomUUID(), 'If-Match': `"${revisions.product}:${revisions.profile}"`, }, }), categoryOptions: (profileId: string, platformId: string, search?: string) => api.get( `/product-platform-profiles/${profileId}/category-options`, { params: search ? { q: search } : undefined, headers: { 'X-Atlas-Platform-Id': platformId }, } ), syncCategoryTree: (profileId: string, platformId: string) => api.post<{ operation: Operation }>( `/product-platform-profiles/${profileId}/category-syncs`, undefined, { headers: { 'X-Atlas-Platform-Id': platformId, 'Idempotency-Key': crypto.randomUUID(), }, } ), attributeSchema: (profileId: string, platformId: string, categoryId?: string | null) => api.get( `/product-platform-profiles/${profileId}/attribute-schema`, { params: categoryId ? { category_id: categoryId } : undefined, headers: { 'X-Atlas-Platform-Id': platformId }, } ), syncAttributeSchema: (profileId: string, platformId: string, categoryId: string) => api.post<{ operation: Operation }>( `/product-platform-profiles/${profileId}/attribute-schema-syncs`, undefined, { params: { category_id: categoryId }, headers: { 'X-Atlas-Platform-Id': platformId, 'Idempotency-Key': crypto.randomUUID(), }, } ), attributeDictionary: ( profileId: string, platformId: string, dictionaryId: string, search?: string, categoryId?: string | null ) => api.get<{ items: ProductAttributeDictionaryValue[]; next_cursor: string | null }>( `/product-platform-profiles/${profileId}/attribute-dictionaries/${encodeURIComponent(dictionaryId)}`, { params: { ...(categoryId ? { category_id: categoryId } : {}), ...(search ? { q: search } : {}), }, headers: { 'X-Atlas-Platform-Id': platformId }, } ), syncAttributeDictionary: ( profileId: string, platformId: string, dictionaryId: string, categoryId: string, query: string ) => api.post<{ operation: Operation }>( `/product-platform-profiles/${profileId}/attribute-dictionaries/${encodeURIComponent(dictionaryId)}/syncs`, undefined, { params: { category_id: categoryId, q: query }, headers: { 'X-Atlas-Platform-Id': platformId, 'Idempotency-Key': crypto.randomUUID(), }, } ), operation: (operationId: string) => api.get(`/operations/${operationId}`), };