# 商品

## product_create

存一個商品：名稱、品號、說明、每個幣別一個單價。

給 Agent 的原文：

> Save a product (name, item code, description, one unit price per currency). A taken item code returns PRODUCT_REF_TAKEN.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `name` | string | 必填 |  |
| `ref` | string |  | Item code; unique in the workspace (case-sensitive) when not empty |
| `description` | string |  | Up to 200 characters, copied into order items |
| `prices` | Price[] | 必填 | One unit price per currency, at least one |
| `prices[].currency` | string | 必填 | An enabled currency of the workspace, e.g. TWD |
| `prices[].unit_price` | string | 必填 | Amount as a string, e.g. "30000" |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`products:manage`

寫入、核可：不用

## product_delete

刪除一個商品；已經成立的訂單和報價單不受影響，品號之後可以再用。

給 Agent 的原文：

> Delete a product. Orders and quotes already created do not change; the item code can be used again.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `product` | string | 必填 | Item code (ref, exact match) or product id |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`products:manage`

寫入、核可：不用

## product_get

用品號或 id 查一個商品，附 version（product_update 要用）。

給 Agent 的原文：

> Get one product by item code or id, with its version (needed by product_update).

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `product` | string | 必填 | Item code (ref, exact match) or product id |

授權項目：`products:read`

核可：不用

## product_search

用名稱或品號找存好的商品，照名稱排序。訂單不會連到商品：要自己把名稱、品號、說明和訂單幣別的單價抄進 order_create 或 quote_create 的品項。

給 Agent 的原文：

> Search saved products by name or item code, ordered by name. Copy name, ref, description and the unit price of the
> order's currency into the items of order_create or quote_create yourself; orders are not linked to products.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `keyword` | string |  | Part of the product name or item code (ref) |
| `limit` | integer |  | default: 20 |
| `cursor` | string（可以是 null） |  |  |

授權項目：`products:read`

核可：不用

## product_update

整份換掉商品的資料；prices 沒列的幣別會拿掉。已經成立的訂單和報價單不受影響。

給 Agent 的原文：

> Replace a product's fields; currencies not listed in prices are removed. Orders and quotes already created do not change.

| 參數 | 型別 | 必填 | 說明 |
| --- | --- | --- | --- |
| `name` | string | 必填 |  |
| `ref` | string |  | Item code; unique in the workspace (case-sensitive) when not empty |
| `description` | string |  | Up to 200 characters, copied into order items |
| `prices` | Price[] | 必填 | One unit price per currency, at least one |
| `prices[].currency` | string | 必填 | An enabled currency of the workspace, e.g. TWD |
| `prices[].unit_price` | string | 必填 | Amount as a string, e.g. "30000" |
| `product` | string | 必填 | Item code (ref, exact match) or product id |
| `version` | integer | 必填 | The version from product_get; a different one returns CONCURRENT_MODIFICATION |
| `idempotency_key` | string | 必填 | Required for every call that writes (not for dry_run). The same key within 24 hours returns the first result instead of doing it again. |

授權項目：`products:manage`

寫入、核可：不用
