# CreateShiftSchedule

## Permission Scope

shiftSchedule

## Overview

createShiftSchedule opens a shift schedule period in `DRAFT`. The period is the from/to a planner enters when generating shifts, so a generation run calls this once and then hangs its Shifts off the returned shift schedule.

## Business Rules

- `startDate` and `endDate` are both required; `endDate` must be on or after `startDate`
- The shift schedule is created in `DRAFT` with `confirmedAt` null
- Overlapping periods are **allowed**: membership is the explicit `Shift.shiftScheduleId` FK, so two shift schedules covering the same dates (another site, a supplementary 応援 shift schedule, a partial revision) are unambiguous and are not rejected
- Creating a shift schedule does not create any Shift; the period starts empty

## Process Flow

```mermaid
flowchart TD
    A[Receive startDate and endDate] --> B{Both supplied?}
    B -->|No| BX[Return error: MISSING_REQUIRED_FIELD]
    B -->|Yes| C{endDate on or after startDate?}
    C -->|No| CX[Return error: INVALID_DATE_RANGE]
    C -->|Yes| D[Insert ShiftSchedule with status DRAFT]
    D --> E[Return created shiftSchedule]
```

## External Dependencies

- [shiftSchedule::ShiftSchedule](../model/ShiftSchedule.md) model - the entity this command creates

## Error Scenarios

- **MISSING_REQUIRED_FIELD**: a required field is missing
- **INVALID_DATE_RANGE**: endDate precedes startDate

## Test Cases

- createShiftSchedule creates a shiftSchedule in DRAFT with confirmedAt null
- a single-day period is accepted
- two shiftSchedules covering the same period are both accepted
- throws INVALID_DATE_RANGE when endDate precedes startDate
- throws MISSING_REQUIRED_FIELD when startDate or endDate is missing
