# Delete 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 delete a leaf category that has no child categories and no product assignments, so that I can remove obsolete categories from the 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{Confirm delete}
    C -- Confirmed --> D{Has child categories?}
    D -- Yes --> E[Error: Cannot delete category with child categories]
    D -- No --> F{Has product assignments?}
    F -- Yes --> G[Error: Cannot delete category with assigned products]
    F -- No --> H[Category deleted]
    H --> I[Category List Screen]
```

## Scenario Patterns

- Successful delete: category has no children and no product assignments; it is permanently removed
- Has children error: attempting to delete a category that has one or more child categories is rejected
- Has products error: attempting to delete a category that has one or more product assignments is rejected

## Test Cases

- Given a leaf category with no children and no product assignments, the category is deleted successfully
- Given a category with at least one child category, deletion fails with a has children error
- Given a category with at least one product assignment, deletion fails with a has products 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.
 -->

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