# category-management

## Overview

Manages hierarchical product categories and product-to-category assignments. Product managers create, edit, move, and delete categories, and assign or remove products from categories. Viewers can browse the category tree.

## Actors Involved

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

## Flow Diagram

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

    PM->>System: Create Category
    alt Valid
        System-->>PM: Category created
    else Duplicate code
        System-->>PM: Error: Category code already exists
    end
    PM->>System: Edit Category
    System-->>PM: Category name updated
    PM->>System: Move Category (reparent)
    alt Valid
        System-->>PM: Category moved
    else Circular reference
        System-->>PM: Error: Cannot set parent to a descendant
    end
    PM->>System: Assign Product to Category
    System-->>PM: Product assigned
    PM->>System: Remove Product from Category
    System-->>PM: Product removed
    PM->>System: Browse Category List
    System-->>PM: Category tree
    PM->>System: View Category Detail
    System-->>PM: Category details with assigned products
    V->>System: Browse Category List
    System-->>V: Category tree
    V->>System: View Category Detail
    System-->>V: Category details with assigned products
    alt Delete
        PM->>System: Delete Category
        alt No children or assignments
            System-->>PM: Category deleted
        else Has children
            System-->>PM: Error: Cannot delete category with child categories
        else Has product assignments
            System-->>PM: Error: Cannot delete category with assigned products
        end
    end
```

## Stories

- [Create Category](./story/product-manager--create-category.md)
- [Edit Category](./story/product-manager--edit-category.md)
- [Move Category](./story/product-manager--move-category.md)
- [Delete Category](./story/product-manager--delete-category.md)
- [Assign Product to Category](./story/product-manager--assign-product-to-category.md)
- [Remove Product from Category](./story/product-manager--remove-product-from-category.md)
- [Browse Category List (Product Manager)](./story/product-manager--browse-category-list.md)
- [View Category Detail (Product Manager)](./story/product-manager--view-category-detail.md)
- [Browse Category List (Viewer)](./story/viewer--browse-category-list.md)
- [View Category Detail (Viewer)](./story/viewer--view-category-detail.md)
