import request from '@/utils/request.js'

// ─── Warehouses ──────────────────────────────────────────────────────────────
export const warehouseApi = {
  getList: (params) => request.get('/inventory/warehouses', { params }),
  getDetail: (id) => request.get(`/inventory/warehouses/${id}`),
  create: (data) => request.post('/inventory/warehouses', data),
  update: (id, data) => request.put(`/inventory/warehouses/${id}`, data),
  delete: (id) => request.delete(`/inventory/warehouses/${id}`)
}

// ─── Suppliers ───────────────────────────────────────────────────────────────
export const supplierApi = {
  getList: (params) => request.get('/inventory/suppliers', { params }),
  getDetail: (id) => request.get(`/inventory/suppliers/${id}`),
  create: (data) => request.post('/inventory/suppliers', data),
  update: (id, data) => request.put(`/inventory/suppliers/${id}`, data),
  delete: (id) => request.delete(`/inventory/suppliers/${id}`)
}

// ─── Materials ───────────────────────────────────────────────────────────────
export const materialApi = {
  getList: (params) => request.get('/inventory/materials', { params }),
  getDetail: (id) => request.get(`/inventory/materials/${id}`),
  create: (data) => request.post('/inventory/materials', data),
  update: (id, data) => request.put(`/inventory/materials/${id}`, data),
  delete: (id) => request.delete(`/inventory/materials/${id}`)
}

// ─── Purchase Orders ─────────────────────────────────────────────────────────
export const purchaseOrderApi = {
  getList: (params) => request.get('/inventory/purchase-orders', { params }),
  getDetail: (id) => request.get(`/inventory/purchase-orders/${id}`),
  create: (data) => request.post('/inventory/purchase-orders', data),
  update: (id, data) => request.put(`/inventory/purchase-orders/${id}`, data),
  delete: (id) => request.delete(`/inventory/purchase-orders/${id}`),
  audit: (id, data) => request.put(`/inventory/purchase-orders/${id}/audit`, data)
}

// ─── Stock Movements ─────────────────────────────────────────────────────────
export const stockMovementApi = {
  getList: (params) => request.get('/inventory/stock-movements', { params }),
  getDetail: (id) => request.get(`/inventory/stock-movements/${id}`),
  create: (data) => request.post('/inventory/stock-movements', data),
  confirm: (id) => request.put(`/inventory/stock-movements/${id}/confirm`)
}

// ─── Inventories ─────────────────────────────────────────────────────────────
export const inventoryApi = {
  getList: (params) => request.get('/inventory/inventories', { params })
}

// ─── Stock Query ─────────────────────────────────────────────────────────────
export const stockApi = {
  getList: (params) => request.get('/inventory/stock', { params }),
  export: (params) => request.get('/inventory/stock/export', { params, responseType: 'blob' })
}

// ─── Transfer Orders ─────────────────────────────────────────────────────────
export const transferApi = {
  getList: (params) => request.get('/inventory/transfers', { params }),
  getDetail: (id) => request.get(`/inventory/transfers/${id}`),
  create: (data) => request.post('/inventory/transfers', data),
  confirm: (id) => request.put(`/inventory/transfers/${id}/confirm`),
  cancel: (id) => request.put(`/inventory/transfers/${id}/cancel`)
}

// ─── Inventory Checks ────────────────────────────────────────────────────────
export const inventoryCheckApi = {
  getList: (params) => request.get('/inventory/checks', { params }),
  getDetail: (id) => request.get(`/inventory/checks/${id}`),
  create: (data) => request.post('/inventory/checks', data),
  complete: (id, data) => request.put(`/inventory/checks/${id}/complete`, data)
}
