# DeleteProductCategory

## Permission Scope

productCatalog

## Overview

deleteProductCategory permanently removes a category from the tree. Only leaf categories (no children) with no product assignments can be deleted. This prevents orphaning child categories or breaking product classification.

## Business Rules

- Target category must exist
- Category must have no child categories
- Category must have no product assignments (no ProductCategoryAssignment records)
- Deletion is permanent and cannot be undone

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{Category exists?}
    B -->|No| C[Return error: CATEGORY_NOT_FOUND]
    B -->|Yes| D{Has child categories?}
    D -->|Yes| E[Return error: HAS_CHILDREN]
    D -->|No| F{Has product assignments?}
    F -->|Yes| G[Return error: HAS_ASSIGNMENTS]
    F -->|No| H[Delete category record]
    H --> I[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **CATEGORY_NOT_FOUND**: Specified category ID does not exist
- **HAS_CHILDREN**: Category has child categories and cannot be deleted
- **HAS_ASSIGNMENTS**: Category has product assignments and cannot be deleted

## Test Cases

- should return CategoryNotFoundError when category does not exist
- should return HasChildrenError when category has children
- should return HasAssignmentsError when category has assignments
- should delete leaf category successfully
