import { apiGet, apiPost } from '@/lib/http'
import type {
  AdminInventoryItemListItem,
  AdminInventorySkuSuggestion,
  AdminPagination,
} from '@/types/admin'

export function fetchAdminInventoryItems(params?: Record<string, unknown>) {
  return apiGet<{ items: AdminInventoryItemListItem[]; pagination: AdminPagination }>(
    '/api/v1/admin/inventory',
    params,
  )
}

export function fetchAdminInventorySkuSuggestions(params?: Record<string, unknown>) {
  return apiGet<{ items: AdminInventorySkuSuggestion[] }>(
    '/api/v1/admin/inventory/sku-suggestions',
    params,
  )
}

export function importAdminInventoryItems(payload: Record<string, unknown>) {
  return apiPost<{ total: number; created: number; duplicated: number }>(
    '/api/v1/admin/inventory/import',
    payload,
  )
}

export function createAdminInventoryItem(payload: Record<string, unknown>) {
  return apiPost<{ inventoryItem: AdminInventoryItemListItem | null }>(
    '/api/v1/admin/inventory',
    payload,
  )
}

export function releaseAdminInventoryItem(inventoryItemId: number | string) {
  return apiPost<{ inventoryItem: AdminInventoryItemListItem | null }>(
    `/api/v1/admin/inventory/${inventoryItemId}/release`,
    {},
  )
}

export function invalidateAdminInventoryItem(
  inventoryItemId: number | string,
  payload?: Record<string, unknown>,
) {
  return apiPost<{ inventoryItem: AdminInventoryItemListItem | null }>(
    `/api/v1/admin/inventory/${inventoryItemId}/invalidate`,
    payload || {},
  )
}
