# Assign Product To Category

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

As a product manager, I want to assign a product to a category, so that customers can discover the product by browsing the category hierarchy.

## 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[Category Detail Screen]
    B --> C[Assign Product Form]
    C --> D{Submit}
    D --> E{Category found?}
    E -- No --> F[Error: Category not found]
    E -- Yes --> G{Product found?}
    G -- No --> H[Error: Product not found]
    G -- Yes --> I{Already assigned?}
    I -- Yes --> J[Error: Product already assigned to this category]
    I -- No --> K[Product assigned to category]
    K --> B
```

## Scenario Patterns

- Successful assignment: both category and product exist and the product is not yet assigned; the assignment is created
- Already assigned error: the product is already assigned to the given category; the request is rejected
- Category not found error: the specified category does not exist
- Product not found error: the specified product does not exist

## Test Cases

- Given a valid category and a valid product not yet assigned, the assignment is created successfully
- Given a product already assigned to the same category, the assignment fails with an already assigned error
- Given a category ID that does not exist, the assignment fails with a category not found error
- Given a product ID that does not exist, the assignment fails with a product not found error

## Screens

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

## Resolvers

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

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