# variant-generation

## Overview

Manages attribute definitions, attribute-to-product assignments, and variant generation. Product managers define attributes (e.g., Color, Size) with values, assign attribute values to products, and generate variants from ACTIVE products. Each generated variant creates an Item in item-management with an auto-generated SKU. Viewers can browse attributes and generated variants.

## Actors Involved

- [product-manager](../../actor/product-manager.md)
- [viewer](../../actor/viewer.md)

## Flow Diagram

```mermaid
sequenceDiagram
    actor PM as product-manager
    actor V as viewer
    participant System

    PM->>System: Create Attribute (e.g., Color)
    System-->>PM: Attribute created
    PM->>System: Create Attribute Value (e.g., Red)
    System-->>PM: Value added to attribute
    PM->>System: Assign Attribute Value to Product
    alt DRAFT or additive on ACTIVE
        System-->>PM: Attribute value assigned
    else ARCHIVED product
        System-->>PM: Error: Cannot modify attributes on ARCHIVED product
    end
    PM->>System: Generate Variants (ACTIVE product)
    alt Valid
        System-->>PM: Variants generated, Items created
    else Not ACTIVE
        System-->>PM: Error: Product must be ACTIVE
    else No attributes
        System-->>PM: Error: No variant axes assigned
    end
    PM->>System: Browse Attribute List
    System-->>PM: Attribute list with value counts
    PM->>System: View Attribute Detail
    System-->>PM: Attribute details with values
    PM->>System: Browse Variant List (per product)
    System-->>PM: Variants with generated Item SKUs
    V->>System: Browse Attribute List
    System-->>V: Attribute list
    V->>System: Browse Variant List (per product)
    System-->>V: Variants with generated Item SKUs
    alt Delete Attribute
        PM->>System: Delete Attribute
        alt Not assigned to any product
            System-->>PM: Attribute deleted
        else Assigned to products
            System-->>PM: Error: Cannot delete assigned attribute
        end
    end
```

## Stories

- [Create Attribute](./story/product-manager--create-attribute.md)
- [Manage Attribute Values](./story/product-manager--manage-attribute-values.md)
- [Assign Attribute to Product](./story/product-manager--assign-attribute-to-product.md)
- [Generate Variants](./story/product-manager--generate-variants.md)
- [Delete Attribute](./story/product-manager--delete-attribute.md)
- [Browse Attribute List (Product Manager)](./story/product-manager--browse-attribute-list.md)
- [View Attribute Detail (Product Manager)](./story/product-manager--view-attribute-detail.md)
- [Browse Variant List (Product Manager)](./story/product-manager--browse-variant-list.md)
- [Browse Attribute List (Viewer)](./story/viewer--browse-attribute-list.md)
- [Browse Variant List (Viewer)](./story/viewer--browse-variant-list.md)
