# CreateProductAttributeValue

## Permission Scope

productCatalog

## Overview

createProductAttributeValue creates a new predefined value for an existing attribute. Values define the available options for that attribute (e.g., adding "Yellow" to a Color attribute). Products using this attribute can then include the new value in variant generation.

## Business Rules

- Target attribute must exist
- Value label is required and must be unique within the parent attribute
- Values can be added at any time, regardless of whether the attribute is assigned to products

## Process Flow

```mermaid
flowchart TD
    A[Receive create value request] --> B{Attribute exists?}
    B -->|No| C[Return error: ATTRIBUTE_NOT_FOUND]
    B -->|Yes| D{Label provided and non-empty?}
    D -->|No| E[Return error: INVALID_LABEL]
    D -->|Yes| F{Label unique within attribute?}
    F -->|No| G[Return error: DUPLICATE_VALUE]
    F -->|Yes| H[Create attribute value record]
    H --> I[Return created value]
```

## External Dependencies

- None

## Error Scenarios

- **ATTRIBUTE_NOT_FOUND**: Specified attribute ID does not exist
- **INVALID_LABEL**: Label is empty or blank
- **DUPLICATE_VALUE**: A value with the same label already exists for this attribute

## Test Cases

- returns error when attribute not found
- returns error when label is empty
- returns error when label already exists
- creates value successfully
