# Phase 4 — Flight schedule management

Phase 4 adds tenant-scoped recurring schedule templates and dated flight records without introducing financial or maintenance modules.

## Scheduling behavior

- Templates hold flight number, route, local station times, IANA timezones, operating weekdays, effective dates, type/default aircraft, turnaround, flight type, and status.
- Generation converts station-local template times to UTC with `DateTimeImmutable` and `DateTimeZone`, including overnight arrivals and daylight-saving transitions.
- The database prevents duplicate airline/flight-number/operating-date/origin records.
- Daily, weekly, monthly, aircraft-timeline, route, and full-list views share server-side filters.
- CSV imports use the same backend validation as manual flight creation; exports contain UTC schedule values.

## Conflict detection

Conflict detection runs in the service layer after creation, edits, generation, assignment, import, and bulk changes. Open findings are resolved before a fresh set is persisted. Rules cover aircraft overlaps, turnaround gaps, maintenance/grounded/out-of-service status, type mismatch, route range, airport operating-hour windows, expired documents, and duplicate flight numbers.

Aircraft maintenance conflicts currently use the fleet operational status because the maintenance module is intentionally outside Phase 4.

## Security and records

- Routes and service methods both enforce granular `flights.*` permissions.
- Mutating endpoints require CSRF tokens.
- Repository queries scope operational data by `airline_id` and use prepared PDO statements.
- Flight status and aircraft assignment changes are append-only histories.
- Schedule templates, generation, flight changes, bulk operations, imports, exports, notes, and status changes are audited.
