-- Add coaster-specific multi-select fields for track material, support material, and propulsion method

-- Update rides table
ALTER TABLE rides 
  ALTER COLUMN track_material TYPE TEXT[] USING 
    CASE 
      WHEN track_material IS NULL THEN NULL 
      ELSE ARRAY[track_material]
    END,
  ADD COLUMN IF NOT EXISTS support_material TEXT[],
  ADD COLUMN IF NOT EXISTS propulsion_method TEXT[];

-- Update ride_versions table
ALTER TABLE ride_versions 
  ALTER COLUMN track_material TYPE TEXT[] USING 
    CASE 
      WHEN track_material IS NULL THEN NULL 
      ELSE ARRAY[track_material]
    END,
  ADD COLUMN IF NOT EXISTS support_material TEXT[],
  ADD COLUMN IF NOT EXISTS propulsion_method TEXT[];

-- Update ride_submissions table
ALTER TABLE ride_submissions 
  ALTER COLUMN track_material TYPE TEXT[] USING 
    CASE 
      WHEN track_material IS NULL THEN NULL 
      ELSE ARRAY[track_material]
    END,
  ADD COLUMN IF NOT EXISTS support_material TEXT[],
  ADD COLUMN IF NOT EXISTS propulsion_method TEXT[];

-- Create indexes for efficient filtering
CREATE INDEX IF NOT EXISTS idx_rides_track_material ON rides USING GIN(track_material);
CREATE INDEX IF NOT EXISTS idx_rides_support_material ON rides USING GIN(support_material);
CREATE INDEX IF NOT EXISTS idx_rides_propulsion_method ON rides USING GIN(propulsion_method);

-- Add comments for documentation
COMMENT ON COLUMN rides.track_material IS 'Array of track materials used in the ride (e.g., wood, steel, hybrid)';
COMMENT ON COLUMN rides.support_material IS 'Array of support materials used in the ride (e.g., steel, wood, concrete)';
COMMENT ON COLUMN rides.propulsion_method IS 'Array of propulsion methods used in the ride (e.g., chain_lift, lsm_launch, hydraulic_launch)';