# DeleteTimeEntryCode

## Permission Scope

`timeEntryCode`

## Overview

Removes a `TimeEntryCode` only when it is referenced by no `WorkRule` premium-category pin, preserving historical calculated results whose traceability depends on the code's `key`.

## Business Rules

- Deletion is rejected if the code is referenced by any `WorkRule` premium-category pin (premium/break/overtime treatment)
- A code that has been referenced historically but no longer is may still be deleted; the guard checks current references, not history retroactively pinned in calculated results by key
- Deletion is a hard delete of the catalog entry once safe to remove

## Process Flow

```mermaid
flowchart TD
    A[Receive code id] --> B{Code exists?}
    B -- No --> C[Reject: TIME_ENTRY_CODE_NOT_FOUND]
    B -- Yes --> D{Referenced by any WorkRule premium-category pin?}
    D -- Yes --> E[Reject: TIME_ENTRY_CODE_IN_USE]
    D -- No --> F[Delete TimeEntryCode]
```

## External Dependencies

- [time-tracking::TimeEntryCode](../model/TimeEntryCode.md) model — the entity this command deletes
- [time-tracking::WorkRule](../model/WorkRule.md) model — checked for premium-category pin references by `category`/`key`

## Error Scenarios

- **TIME_ENTRY_CODE_NOT_FOUND**: no TimeEntryCode exists for the given id
- **TIME_ENTRY_CODE_IN_USE**: the code is referenced by a `WorkRule` premium-category pin and cannot be deleted

## Test Cases

- deleting a code referenced by a WorkRule premium-category pin is rejected
- deleting a code with no remaining references succeeds
- deleting a non-existent code id is rejected

