-- Migration: Add custom_loop stage type support
-- Date: 2025-11-12
-- Description: Add support for custom loop courses with variable lap distances and camera positions

-- Add lap_distances field to store array of distances for each lap
ALTER TABLE stages 
ADD COLUMN lap_distances JSON DEFAULT NULL COMMENT 'Array of distances for each lap in meters (for custom_loop type)';

-- Add camera_positions field to store camera placement data
ALTER TABLE stages 
ADD COLUMN camera_positions JSON DEFAULT NULL COMMENT 'Array of camera positions with distance and checkpoint info';

-- Update type enum to include custom_loop (if using ENUM, otherwise skip)
-- ALTER TABLE stages MODIFY COLUMN type ENUM('gpx', 'laps', 'point_to_point', 'custom_loop') NOT NULL DEFAULT 'gpx';

-- Example data structure for custom_loop:
-- lap_distances: [1200, 1500, 1200] // 3 laps with different distances
-- camera_positions: [
--   {"position": 0, "lap": 1, "distance_in_lap": 0, "checkpoint_id": "uuid", "name": "Start/Finish"},
--   {"position": 600, "lap": 1, "distance_in_lap": 600, "checkpoint_id": "uuid", "name": "Mid Lap 1"},
--   {"position": 1200, "lap": 2, "distance_in_lap": 0, "checkpoint_id": "uuid", "name": "Lap 2 Start"},
--   {"position": 1950, "lap": 2, "distance_in_lap": 750, "checkpoint_id": "uuid", "name": "Mid Lap 2"},
--   {"position": 2700, "lap": 3, "distance_in_lap": 0, "checkpoint_id": "uuid", "name": "Lap 3 Start"},
--   {"position": 3900, "lap": 3, "distance_in_lap": 1200, "checkpoint_id": "uuid", "name": "Finish"}
-- ]
