# DeleteProductAttribute

## Permission Scope

productCatalog

## Overview

deleteProductAttribute permanently removes a product attribute from the system. An attribute can only be deleted if it is not currently assigned to any product. This prevents orphaning attribute references on existing products.

## Business Rules

- Target attribute must exist
- Attribute deletion is blocked if the attribute is assigned to any product (has any ProductAttributeAssignment records)
- Deleting an attribute also removes all associated ProductAttributeValues

## Process Flow

```mermaid
flowchart TD
    A[Receive delete request] --> B{Attribute exists?}
    B -->|No| C[Return error: ATTRIBUTE_NOT_FOUND]
    B -->|Yes| D{Assigned to any product?}
    D -->|Yes| E[Return error: ATTRIBUTE_IN_USE]
    D -->|No| F[Remove attribute values]
    F --> G[Delete attribute record]
    G --> H[Return success]
```

## External Dependencies

- None

## Error Scenarios

- **ATTRIBUTE_NOT_FOUND**: Specified attribute ID does not exist
- **ATTRIBUTE_IN_USE**: Attribute is assigned to one or more products and cannot be deleted

## Test Cases

- returns error when attribute not found
- returns error when attribute is in use
- deletes attribute and values successfully
