# ResetNotificationPreferences

## Permission Scope

preferenceSelf

## Overview

resetNotificationPreferences hard-deletes every NotificationPreference row owned by the calling user in a single transaction, reverting their preference matrix to the module's opt-in-by-default behaviour. The caller must equal the target user; cross-user reset attempts are rejected. The operation is idempotent — running it on a user with no rows is a successful no-op.

## Business Rules

- `userId` is required
- The caller's userId must equal `userId`
- All NotificationPreference rows where `userId = caller.userId` are deleted in a single transaction
- Idempotent: running on a user with no rows is a successful no-op
- The returned `deletedCount` is the number of preference rows deleted

## Process Flow

```mermaid
flowchart TD
    A[Receive reset request] --> B{Caller.userId == target userId?}
    B -->|No| C[Return FORBIDDEN]
    B -->|Yes| D[Hard-delete all NotificationPreference rows where userId = caller.userId]
    D --> F[Return deletion count]
```

## External Dependencies

- User-management context - The caller's userId is read from the authenticated context to enforce self-service editing

## Error Scenarios

- **FORBIDDEN**: Caller is not authorized to perform this operation in the target scope

## Test Cases

- deletes every NotificationPreference row owned by the calling user
- returns FORBIDDEN when the caller's userId does not equal the target userId
- is idempotent on a user with no preference rows (returns success with deletion count zero)
- after reset, dispatching an optional-category event delivers on every default channel (default opt-in restored)
