# Reference: Copy quote info to payload

This file holds the detailed mapping rules and a worked example. The main procedure is in `SKILL.md`.

## Source structure (quote data)

```
{
  "quote": {
    "id": "...",                     // the quote id
    "customerId": "...",
    "customerCategoryId": "...",
    "distributionChannelId": "...",
    "attributes": { ... },
    "orderItemIds": [ ... ],         // root product-item ids
    "opportunityId": "...",
    ...
  },
  "items": [
    { "id": "...", "type": "productItem",  ... },
    { "id": "...", "type": "locationItem", ... },
    { "id": "...", "type": "alertItem",    ... },
    ...
  ]
}
```

## Target structure (quote command skeleton)

The command shape **varies greatly**. Adapt to whatever keys exist. A common example:

```
{
  "businessCommand": "quote_init",
  "businessCommandAttributes": { ... },
  "id": "{{quoteId}}",
  "items": [],
  "batchCommands": [
    {
      "businessCommand": "product_items_modify",
      "businessCommandAttributes": { "date": "..." },
      "id": "{{quoteId}}",
      "items": [ { "id": "...", "type": "productItem" }, ... ]
    }
  ],
  "quoteCmd": {
    "attributes": {},
    "customerId": "...",
    "customerCategoryId": "...",
    "distributionChannelId": "..."
  }
}
```

## Field mapping (source → target)

Apply a mapping only when the target has a slot for it. Match by key name and meaning.

| Target field (wherever it appears)                | Source value                              |
| ------------------------------------------------- | ----------------------------------------- |
| `{{quoteId}}` placeholder, top-level `id`, batch `id` | `quote.id`                            |
| `quoteCmd.customerId` / any `customerId`          | `quote.customerId`                        |
| `quoteCmd.customerCategoryId` / `customerCategoryId` | `quote.customerCategoryId`             |
| `quoteCmd.distributionChannelId` / `distributionChannelId` | `quote.distributionChannelId`   |
| `quoteCmd.attributes` (when empty and desired)    | `quote.attributes` (only if user wants it)|
| `opportunityId`                                   | `quote.opportunityId`                     |
| `marketId` on items                               | item's `marketId` from source             |

Notes:
- If the skeleton already has a hardcoded value (e.g. a sample `customerId`) and it differs from the source, replace it with the source value — the point is to reflect the source quote. Mention the replacement in the summary.
- If the skeleton has a `date`/timestamp the source doesn't provide (e.g. `businessCommandAttributes.date`), leave the skeleton's value as-is unless the user gives one.
- `quoteCmd.attributes` is often intentionally `{}`. Do **not** dump `quote.attributes` into it unless the user asks — attribute keys in the command context may differ.

## Item-selection rules

- **Product items:** items in the source with `"type": "productItem"`. These are the ones that typically go into a `product_items_modify` (or similar) block's `items` array as `{ "id": <sourceId>, "type": "productItem" }`.
- **Location items** (`"type": "locationItem"`) and **alert items** (`"type": "alertItem"`) are usually *not* copied into a product-items block. Copy them only where the skeleton has a matching slot for that type.
- **Copy all matching items** from the source into the target's item slot, preserving order and ids, using the field shape the skeleton's item entries use (often just `id` + `type`).
- Copy everything **unchanged** unless the user specifies a change (e.g. "set quantity to 2 on the Fibre item", "drop the DISCONNECT item", "change action to ADD"). Apply only what they name.
- Root vs. child products: `quote.orderItemIds` lists the root product ids. If the skeleton only wants roots, use those; if it wants all product items, use every `productItem`. When unclear, default to all `productItem`s and note it.

## Worked example

**Source (quote data):** `quote.id = d968445a-f813-4be1-899d-e06accb6473b`, `customerId = slotest`, `customerCategoryId = 0ded2167-c41b-4f58-9941-dbd247b1985d`, `distributionChannelId = CPMS`. Product items in `items`:
`9b4be199-4b65-4ec0-b54b-d2f61366c9ed`, `81a3fb42-31a5-4ea8-a668-8973e57aa2f9`, `c6a7aacd-8d3b-4c44-8680-829b15be5c06`, `fcd59bff-4339-4fea-8168-bb8598e98085` (plus location and alert items, which are not product items).

**Skeleton:** the `quote_init` + `product_items_modify` command shown above.

**Filled result:**

```json
{
  "businessCommand": "quote_init",
  "businessCommandAttributes": {
    "itemTypesScope": []
  },
  "id": "d968445a-f813-4be1-899d-e06accb6473b",
  "items": [],
  "batchCommands": [
    {
      "businessCommand": "product_items_modify",
      "businessCommandAttributes": {
        "date": "2026-08-28T10:00:00.000-03:00"
      },
      "id": "d968445a-f813-4be1-899d-e06accb6473b",
      "items": [
        { "id": "9b4be199-4b65-4ec0-b54b-d2f61366c9ed", "type": "productItem" },
        { "id": "81a3fb42-31a5-4ea8-a668-8973e57aa2f9", "type": "productItem" },
        { "id": "c6a7aacd-8d3b-4c44-8680-829b15be5c06", "type": "productItem" },
        { "id": "fcd59bff-4339-4fea-8168-bb8598e98085", "type": "productItem" }
      ]
    }
  ],
  "quoteCmd": {
    "attributes": {},
    "customerId": "slotest",
    "customerCategoryId": "0ded2167-c41b-4f58-9941-dbd247b1985d",
    "distributionChannelId": "CPMS"
  }
}
```

Summary in this example: filled `{{quoteId}}` (both occurrences) from `quote.id`; set `customerId`, `customerCategoryId`, `distributionChannelId` from the source (replacing the skeleton's sample values); copied all 4 `productItem`s into the `product_items_modify` block unchanged; left `businessCommandAttributes.date` as-is (not present in source); kept `quoteCmd.attributes` empty (not requested).
