# AssignProductToCategory

## Permission Scope

product

## Overview

assignProductToCategory creates a many-to-many link between a product and a product category. Products can be assigned to multiple categories for multi-dimensional classification. Assignment is idempotent — assigning an already-assigned product returns the existing record without error.

## Business Rules

- Target product must exist
- Target category must exist
- The (productId, categoryId) combination must be unique
- Assignment is idempotent — if the assignment already exists, return the existing record
- Products in any status (DRAFT, ACTIVE, ARCHIVED) can be assigned to categories

## Process Flow

```mermaid
flowchart TD
    A[Receive assign request] --> B{Product exists?}
    B -->|No| C[Return error: PRODUCT_NOT_FOUND]
    B -->|Yes| D{Category exists?}
    D -->|No| E[Return error: CATEGORY_NOT_FOUND]
    D -->|Yes| F{Assignment already exists?}
    F -->|Yes| G[Return existing assignment]
    F -->|No| H[Create assignment record]
    H --> I[Return created assignment]
```

## External Dependencies

- None

## Error Scenarios

- **PRODUCT_NOT_FOUND**: Specified product ID does not exist
- **CATEGORY_NOT_FOUND**: Specified category ID does not exist

## Test Cases

- should return ProductNotFoundError when product does not exist
- should return CategoryNotFoundError when category does not exist
- should create assignment successfully
- should return existing assignment when already assigned (idempotent)
