# DeleteHolidayCalendar

## Permission Scope

`holidayCalendar`

## Overview

Removes a holiday calendar that is referenced by no `CompanyHoliday` and no `WorkRule`, preserving scoped holiday determination for any calendar still in use. Since HolidayCalendar is master data, deletion is a direct removal of the record rather than closing an effective-dated generation.

## Business Rules

- Deletion is rejected if the calendar is still referenced by any `CompanyHoliday` (`calendarId`) or any `WorkRule` (`holidayCalendarId`)
- A calendar with no remaining references may be deleted outright; there is no generation history to preserve for HolidayCalendar
- After deletion, the calendar's `key` becomes available for reuse by a new calendar

## Process Flow

```mermaid
flowchart TD
    A[Receive calendar id] --> B{Calendar exists?}
    B -- No --> C[Reject: HOLIDAY_CALENDAR_NOT_FOUND]
    B -- Yes --> D{Referenced by any CompanyHoliday or WorkRule?}
    D -- Yes --> E[Reject: CALENDAR_IN_USE]
    D -- No --> F[Delete HolidayCalendar]
```

## External Dependencies

- [time-tracking::HolidayCalendar](../model/HolidayCalendar.md) model — the entity this command deletes
- [time-tracking::CompanyHoliday](../model/CompanyHoliday.md) model — checked for `calendarId` references
- [time-tracking::WorkRule](../model/WorkRule.md) model — checked for `holidayCalendarId` references

## Error Scenarios

- **HOLIDAY_CALENDAR_NOT_FOUND**: no HolidayCalendar exists for the given id
- **CALENDAR_IN_USE**: the calendar is still referenced by a CompanyHoliday or WorkRule and cannot be deleted

## Test Cases

- deleting a calendar referenced by a `CompanyHoliday` is rejected
- deleting a calendar referenced by a `WorkRule` is rejected
- deleting a calendar with no remaining references succeeds
- deleting a non-existent calendar id is rejected
