# Assign Attribute To Product

<!-- User story defining a specific requirement within a business flow.
The name of the story should start with the actor followed by `--` and the story name.
 -->

<!-- This section should contain the following subsections in order: -->
<!-- 1. ## User Story (required) -->
<!-- 2. ## Story Diagram (required) -->
<!-- 3. ## Scenario Patterns (required) -->
<!-- 4. ## Test Cases (required) -->
<!-- 5. ## Screens (required) -->
<!-- 6. ## Resolvers (required) -->

## User Story

<!-- Define the user story in the format:
As a [role], I want [goal], so that [benefit].
 -->

As a product manager, I want to assign attributes to a product, so that the product's variant axes are defined and variants can be generated from attribute value combinations.

## Story Diagram

<!-- Mermaid flowchart showing user interactions with screens.
Focus on actors, UI screens, and business outcomes.
Avoid technical details (APIs, databases, endpoints).
 -->

<!-- Code block requirements: -->
<!-- Minimum 1 mermaid code blocks required -->

```mermaid
flowchart TD
    A([Product Manager]) --> B[Product Detail Screen]
    B --> C{Check Product Status}
    C -- ARCHIVED --> D[Show Error: Cannot Modify Archived Product]
    C -- DRAFT --> E[Assign Attribute Form]
    C -- ACTIVE --> E
    E --> F{Validate}
    F -- No attribute selected --> G[Show Error: Required Field Missing]
    F -- Valid, DRAFT --> H[Attribute Assigned to Product]
    F -- Valid, ACTIVE --> I{Is Assignment Additive?}
    I -- Removing existing --> J[Show Error: Cannot Remove Attribute from Active Product]
    I -- Adding new --> H
    H --> B
    G --> E
```

## Scenario Patterns

<!-- List requirements: -->
<!-- Minimum 1 unordered lists required -->
<!-- Minimum 1 items per list -->

- Product manager assigns an attribute to a DRAFT product and the attribute appears on the product's variant configuration.
- Product manager assigns an additional attribute to an ACTIVE product and the attribute is added without removing existing ones.
- Attempting to remove an attribute from an ACTIVE product results in an error.
- Attempting to assign any attribute to an ARCHIVED product results in an error.

## Test Cases

<!-- List requirements: -->
<!-- Minimum 1 items per list -->

- Given a DRAFT product, when an attribute is assigned, then the attribute is linked to the product.
- Given an ACTIVE product, when a new attribute is assigned, then it fails because axis structure is locked.
- Given an ACTIVE product, when an attempt is made to remove an attribute, then an error is shown.
- Given an ARCHIVED product, when an attribute assignment is attempted, then an error is shown.

## Screens

<!-- Link to screen docs that implement this story's UI.
 -->

<!-- List requirements: -->
<!-- Minimum 1 unordered lists required -->
<!-- Minimum 1 items per list -->

- [product-detail](../../../screen/product-detail.md)

## Resolvers

<!-- Link to resolver docs that implement this story's backend operations.
Write "None" if this story does not require any resolvers.
 -->

<!-- List requirements: -->
<!-- Minimum 1 items per list -->

- [updateProductAttributes](../../../resolver/updateProductAttributes.md)
