import { kbxApi } from '../../../http/generated/kbxApiClient'
import type { KbxAuditEntry } from '@kbx/contracts'
import type { ItemMasterRow } from './item.definition'
export interface ItemSearchResponse { items: ItemMasterRow[]; totalCount: number }
export interface ItemSaveRequest { id?:string; version?:number; code:string; name:string; categoryName?:string; specification?:string; unit:string; barcode?:string; defaultWarehouseId?:string|null; lotManaged:boolean; expiryManaged:boolean }
export interface ItemSaveResponse { id:string; version:number; status:string }
export const itemApi = {
  search(keyword = '') { return kbxApi.request<ItemSearchResponse>('erp.items.search', { query: { keyword, page: 1, pageSize: 200 } }) },
  get(id: string) { return kbxApi.request<ItemMasterRow>('erp.items.get', { path: { id } }) },
  create(body:ItemSaveRequest) { return kbxApi.request<ItemSaveResponse>('erp.items.create', { body }) },
  update(id:string,body:ItemSaveRequest) { return kbxApi.request<ItemSaveResponse>('erp.items.update', { path:{id}, body }) },
  deactivate(id:string,version:number) { return kbxApi.request<ItemSaveResponse>('erp.items.deactivate', { path:{id}, body:{version} }) },
  audit(id:string) { return kbxApi.request<KbxAuditEntry[]>('erp.items.audit', { path:{id} }) },
}
