# CreatePurchasePriceList

## Permission Scope

purchasePricing

## Overview

CreatePurchasePriceList creates a new active supplier-specific price list container for one company. The list provides the parent contract context for later purchase price rules.

## Business Rules

- `companyId`, `supplierId`, and a list name or code are required
- Supplier must exist, be active, and carry the `SUPPLIER` role
- List priority must be valid within the supplier and company scope
- New price lists are created in `ACTIVE` status

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Company exists?}
    B -->|No| C[Return company error]
    B -->|Yes| D{Supplier exists, active, SUPPLIER?}
    D -->|No| E[Return supplier error]
    D -->|Yes| F{Priority valid?}
    F -->|No| G[Return priority error]
    F -->|Yes| H[Insert price list in ACTIVE]
    H --> I[Return created list]
```

## External Dependencies

- [business-partner::GetPartner](../../../business-partner/docs/queries/GetPartner.md) - Validate supplier identity and role classification
- [organization::GetCompany](../../../organization/docs/queries/GetCompany.md) - Validate company scope

## Error Scenarios

- **COMPANY_NOT_FOUND**: Referenced company does not exist
- **SUPPLIER_NOT_FOUND**: Referenced supplier partner does not exist
- **SUPPLIER_NOT_ACTIVE**: Referenced supplier is not in ACTIVE status
- **PARTNER_NOT_SUPPLIER**: Referenced partner does not carry the SUPPLIER role
- **INVALID_LIST_PRIORITY**: List priority conflicts with deterministic supplier or rule ordering

## Test Cases

- creates an active price list for an active supplier
- returns error when company does not exist
- returns error when supplier does not exist
- returns error when supplier is inactive
- returns error when partner is not a supplier
- returns error when list priority is invalid
