# ResolveItemValuationPolicies

## Overview

ResolveItemValuationPolicies reports which valuation policy governs each of a set of items in a company, so other modules can read a posting account off it without reimplementing inventory's precedence or querying its tables.

The company-default fallback matters because an item is assigned its ItemValuation record lazily, on its first valuation-affecting movement. An item ordered but not yet received has no assignment even though the accounts that will govern it are already determined, so resolving this way gives the same answer before and after the first receipt.

Unlike GetItemValuation, this reports the governing policy rather than the association record, and omits an item instead of failing when nothing governs it.

## Business Rules

- Requires `companyId` and `itemIds`
- Duplicate item IDs in `itemIds` collapse to one resolution
- An item with an ItemValuation record in the company resolves to the policy that record references
- An item with no ItemValuation record in the company resolves to the company's default policy — the policy whose `defaultCompanyId` is the company
- An item whose ItemValuation record references a policy that no longer exists falls back to the company's default policy
- An item that resolves to no policy is omitted from the result, so callers can distinguish resolved from unresolved without an error
- Returns an empty list when `itemIds` is empty, without querying
- Resolution is read-only: it never creates the ItemValuation record that a movement would create

## Process Flow

```mermaid
flowchart TD
    A[Receive companyId and itemIds] --> B{Any item IDs?}
    B -->|No| C[Return empty list]
    B -->|Yes| D[SELECT ItemValuation for the items in the company]
    D --> E[SELECT the company's valuation policies]
    E --> F{Item has an assignment to an existing policy?}
    F -->|Yes| G[Resolve to the assigned policy]
    F -->|No| H{Company has a default policy?}
    H -->|Yes| I[Resolve to the default policy]
    H -->|No| J[Omit the item from the result]
    G --> K[Return one resolution per resolved item]
    I --> K
    J --> K
```

## External Dependencies

- None

## Error Scenarios

None. An item that resolves to no policy is omitted from the result rather than raising an error.

## Test Cases

- resolves an item to its assigned valuation policy
- falls back to the company default policy for an item with no valuation record
- falls back to the company default policy when the assigned policy no longer exists
- omits an item when the company has no default policy
- collapses duplicate item IDs into one resolution
- returns empty list without querying when no item IDs are provided
