import { apiGet, apiPost } from '@/lib/http'
import type {
  AdminFulfillmentBindingConfigItem,
  AdminFulfillmentLookupResult,
  AdminObservedProductItem,
} from '@/types/admin'

export function fetchAdminFulfillmentBindingConfigs() {
  return apiGet<{
    filePath: string
    bindings: AdminFulfillmentBindingConfigItem[]
    observedProducts: AdminObservedProductItem[]
  }>('/api/v1/admin/platform-config/fulfillment-bindings')
}

export function lookupAdminFulfillmentBindingOrder(payload: {
  provider?: string
  platform?: string
  shopId: string
  platformOrderId: string
}) {
  return apiPost<AdminFulfillmentLookupResult>(
    '/api/v1/admin/platform-config/fulfillment-bindings/lookup-order',
    payload,
  )
}

export function saveAdminFulfillmentBindingConfigs(payload: {
  bindings: Array<Record<string, unknown>>
}) {
  return apiPost<{
    filePath: string
    bindings: AdminFulfillmentBindingConfigItem[]
  }>('/api/v1/admin/platform-config/fulfillment-bindings', payload)
}
