# CreateProductAttribute

## Permission Scope

productCatalog

## 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 entity with the same code already exists within the scope
- **MISSING_REQUIRED_FIELD**: One or more required fields are missing or empty

## 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
