# CreateProductAttribute

## Overview

createProductAttribute defines a new product attribute with a unique code and display name. All attributes are variant axes — they hold predefined values that drive variant generation. Values are created separately via createProductAttributeValue.

## Business Rules

- Attribute code is required, must be globally unique, and is immutable after creation
- Attribute name is required and must be non-empty

## Process Flow

```mermaid
flowchart TD
    A[Receive create request] --> B{Code provided and unique?}
    B -->|No| C[Return error: DUPLICATE_CODE or MISSING_REQUIRED_FIELD]
    B -->|Yes| D{Name provided?}
    D -->|No| E[Return error: MISSING_REQUIRED_FIELD]
    D -->|Yes| F[Create attribute record]
    F --> G[Return created attribute]
```

## External Dependencies

- None

## Error Scenarios

- **DUPLICATE_CODE**: An attribute with the same code already exists
- **MISSING_REQUIRED_FIELD**: Code or name not provided

## Test Cases

- returns error when code is empty
- returns error when name is empty
- returns error when code already exists
- creates attribute successfully
- passes custom fields through to insert
