# CreateCompanyHoliday

## Permission Scope

`holidayCalendar`

## Overview

Registers a new dated holiday fact — a `calendarId`, a date, its `holidayKind`, and a `name` — in the holiday calendar identified by `calendarId`. This is the data-driven replacement for the legacy hardcoded holiday list: adding a newly declared holiday is a data change, not a code change.

## Business Rules

- `calendarId` must reference an existing [HolidayCalendar](../model/HolidayCalendar.md); the holiday is registered into that calendar
- `holidayDate` must be unique **within its calendar** (`(calendarId, holidayDate)`); registering a second holiday on a date already registered in the same calendar is rejected. The same date may be registered independently in a different calendar
- `holidayKind` must be one of the normalized enum values `STATUTORY` (statutory holiday) or `PRESCRIBED` (prescribed/company holiday); any other value is rejected
- `CompanyHoliday` is a plain dated fact, not effective-dated — creation stores the fact directly with no generation/versioning semantics
- Once created, the holiday is immediately readable by scheduling (scheduled working-day determination) and by calculation (holiday classification/premium) as the single source of holiday truth

## Process Flow

```mermaid
flowchart TD
    A[Receive calendarId, holidayDate, holidayKind, name] --> B{holidayDate already registered in this calendar?}
    B -- Yes --> C[Reject: DUPLICATE_HOLIDAY_DATE]
    B -- No --> D{holidayKind valid enum?}
    D -- No --> E[Reject: INVALID_HOLIDAY_KIND]
    D -- Yes --> F[Create CompanyHoliday fact]
    F --> G[Holiday available to scheduling scheduled working-day determination]
    F --> H[Holiday available to calculation premium/classification]
```

## External Dependencies

- [time-tracking::CompanyHoliday](../model/CompanyHoliday.md) model — the entity this command creates
- [time-tracking::HolidayCalendar](../model/HolidayCalendar.md) model — referenced by `calendarId`; the calendar the holiday is scoped to

## Error Scenarios

- **DUPLICATE_HOLIDAY_DATE**: a holiday is already registered for the given holidayDate within the same calendar
- **INVALID_HOLIDAY_KIND**: `holidayKind` is not one of `STATUTORY` / `PRESCRIBED`

## Test Cases

- registering two holidays on the same date in the same calendar is rejected (`holidayDate` unique per `(calendarId, holidayDate)`)
- registering the same date in two different calendars succeeds
- `holidayKind` accepts only `STATUTORY` / `PRESCRIBED` (rejects unknown values)
- creates the holiday fact with the given `calendarId`, `name`, and `holidayKind`
- a newly created holiday is immediately resolvable by `getCompanyHolidayByDate` for its calendar
- adding a new holiday requires no code change (data-only)

