// One typed client method per UOM endpoint (docs/11-BACKEND-PHASE1.md §2.2, FR-MD-02).
// `list` also backs the GRN/PO line UOM picker.
import { apiRequest, buildQuery } from "@/lib/api-client"
import { PagedResponse } from "@/types/common"
import { CreateUomRequest, Uom } from "@/types/master-data"

export interface ListUomsParams {
  page?: number
  pageSize?: number
  q?: string
  sort?: string
}

export const uomsApi = {
  list(params: ListUomsParams = {}): Promise<PagedResponse<Uom>> {
    return apiRequest<PagedResponse<Uom>>(`/uoms${buildQuery(params)}`)
  },

  create(request: CreateUomRequest): Promise<Uom> {
    return apiRequest<Uom>("/uoms", { method: "POST", body: request })
  },
}
