# CreateSalesPriceRule

## Permission Scope

salesPricing

## Overview

CreateSalesPriceRule creates a draft pricing condition inside a sales price list so customer- or channel-specific selling prices can be resolved deterministically.

## Business Rules

- Record is always created in DRAFT status.
- Unit price must be positive.
- Effective end date cannot precede start date.
- Minimum quantity cannot be negative.

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B[Validate references and required fields]
    B --> C{Validation passed?}
    C -->|No| D[Return validation error]
    C -->|Yes| E[Insert draft SalesPriceRule record]
    E --> F[Return created SalesPriceRule]
```

## External Dependencies

- [item-management::GetItem](../../../item-management/docs/query/GetItem.md) - Validate the referenced sellable item.
- [primitives::GetCurrency](../../../primitives/docs/query/GetCurrency.md) - Validate currency assignment.
- [primitives::GetUnit](../../../primitives/docs/query/GetUnit.md) - Validate sales UoM assignment.
- [getSalesPriceList](../query/GetSalesPriceList.md) - Validate parent price-list scope.

## Error Scenarios

- **SALESPRICERULE_NOT_FOUND**: Referenced SalesPriceRule does not exist
- **PRICE_LIST_NOT_FOUND**: Referenced sales price list does not exist
- **INVALID_UNIT_PRICE**: Unit price must be greater than zero.
- **INVALID_EFFECTIVE_RANGE**: Effective end date precedes start date.

## Test Cases

- creates a draft price rule with item, currency, and UoM context
- throws when required SalesPriceRule fields are missing
- creates the SalesPriceRule in DRAFT status
- throws when the parent price list does not exist
- throws on invalid unit price
- throws on invalid effective date range
