# Feature: Flight Management

## Description
Core REST endpoints for flight lifecycle management including CRUD operations, status retrieval, and waypoint management. This feature provides the fundamental data operations for flight entities.

## Component APIs Implemented
- `create_flight(flight_data: FlightCreateRequest) -> FlightResponse`
- `get_flight(flight_id: str) -> FlightDetailResponse`
- `delete_flight(flight_id: str) -> DeleteResponse`
- `get_flight_status(flight_id: str) -> FlightStatusResponse`
- `update_waypoint(flight_id: str, waypoint_id: str, waypoint: Waypoint) -> UpdateResponse`
- `batch_update_waypoints(flight_id: str, waypoints: List[Waypoint]) -> BatchUpdateResponse`

## REST Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/flights` | Create new flight |
| GET | `/flights/{flightId}` | Get flight details |
| DELETE | `/flights/{flightId}` | Delete flight |
| GET | `/flights/{flightId}/status` | Get processing status |
| PUT | `/flights/{flightId}/waypoints/{waypointId}` | Update single waypoint |
| PUT | `/flights/{flightId}/waypoints/batch` | Batch update waypoints |

## External Tools and Services
- **FastAPI**: Web framework for REST endpoints
- **Pydantic**: Request/response validation and serialization
- **Uvicorn**: ASGI server

## Internal Methods
| Method | Purpose |
|--------|---------|
| `_validate_gps_coordinates(lat, lon)` | Validate GPS coordinate ranges |
| `_validate_camera_params(params)` | Validate camera parameter values |
| `_validate_geofences(geofences)` | Validate geofence polygon data |
| `_build_flight_response(flight_data)` | Build response from F02 result |
| `_build_status_response(status_data)` | Build status response |

## Unit Tests
1. **create_flight validation**
   - Valid request → calls F02.create_flight() and returns 201
   - Missing required field (name) → returns 400
   - Invalid GPS (lat > 90) → returns 400
   - Invalid camera params → returns 400

2. **get_flight**
   - Valid flight_id → returns 200 with flight data
   - Non-existent flight_id → returns 404

3. **delete_flight**
   - Valid flight_id → returns 200
   - Non-existent flight_id → returns 404
   - Processing flight → returns 409

4. **get_flight_status**
   - Valid flight_id → returns 200 with status
   - Non-existent flight_id → returns 404

5. **update_waypoint**
   - Valid update → returns 200
   - Invalid waypoint_id → returns 404
   - Invalid coordinates → returns 400

6. **batch_update_waypoints**
   - Valid batch → returns success with updated_count
   - Empty batch → returns success, updated_count=0
   - Partial failures → returns failed_ids

## Integration Tests
1. **Flight lifecycle**
   - POST /flights → GET /flights/{id} → DELETE /flights/{id}
   - Verify data consistency across operations

2. **Waypoint updates during processing**
   - Create flight → Process frames → Verify waypoints updated
   - Simulate refinement updates → Verify refined=true

3. **Concurrent operations**
   - Create 10 flights concurrently → All succeed
   - Batch update 500 waypoints → All succeed

