# Work Schedule Management

## Overview

Work Schedule Management maintains the effective-dated planned-time baseline for each `Assignment`: the scheduled daily and weekly minutes. It deliberately does not duplicate the employment regime held by `WorkRegime` or bundle regime- and jurisdiction-specific labor-law configuration.

## Business Purpose

- Give downstream calculation and reporting a planned-time baseline per Assignment
- Preserve history through non-overlapping effective-dated generations
- Allow applications to add regime- and country-specific schedule configuration through custom fields
- Keep employment-regime classification in `WorkRegime` rather than storing a second, potentially conflicting value

## Process Flow

```mermaid
flowchart TD
    A[Open WorkSchedule for an Assignment] --> B[Set scheduled daily and weekly minutes]
    B --> C[Create current generation effectiveEnd = null]
    C --> D{Planned-time change on date T?}
    D -- Yes --> E[Close current generation at T - 1 day]
    E --> F[Insert new generation effective on T]
    D -- No --> G{Assignment ended?}
    G -- Yes --> H[Close current generation]
```

## Scenario Patterns

- **Initial baseline**: an Assignment's first generation records its daily and weekly planned minutes
- **Effective-dated change**: changing planned minutes closes the current generation and inserts a non-overlapping successor
- **Terminal close**: closing the current generation without a successor, typically when the Assignment itself ends
- **Application extension**: a consuming app adds regime- or jurisdiction-specific parameters, such as a flex core-time band, through WorkSchedule custom fields

## Test Cases

- creating a schedule stores the daily and weekly planned minutes on an open generation
- changing planned minutes creates a new non-overlapping generation
- querying a past date returns the generation in force then
- a future-dated generation is not returned as current before its start date
- closing the current generation leaves it queryable via asOf

## Reference Links

- Planned-time baseline gap in the source attendance application: https://github.com/tailor-sandbox/Omakase-ERP-attendance/issues/9
- WFM scope and shift scheduling: https://github.com/tailor-sandbox/Omakase-ERP-attendance/issues/11
