-- Phase 9A: Add Critical Foreign Key Indexes for Query Performance
-- These indexes cover the most frequently accessed foreign key relationships

-- Core entity relationships (highest priority)
-- These are queried on EVERY page load for parks/rides to fetch current version data

-- Park version foreign keys
CREATE INDEX IF NOT EXISTS idx_park_versions_park_id 
  ON park_versions(park_id);

CREATE INDEX IF NOT EXISTS idx_park_versions_location_id 
  ON park_versions(location_id);

CREATE INDEX IF NOT EXISTS idx_park_versions_operator_id 
  ON park_versions(operator_id);

CREATE INDEX IF NOT EXISTS idx_park_versions_property_owner_id 
  ON park_versions(property_owner_id);

-- Ride version foreign keys
CREATE INDEX IF NOT EXISTS idx_ride_versions_ride_id 
  ON ride_versions(ride_id);

CREATE INDEX IF NOT EXISTS idx_ride_versions_park_id 
  ON ride_versions(park_id);

CREATE INDEX IF NOT EXISTS idx_ride_versions_manufacturer_id 
  ON ride_versions(manufacturer_id);

CREATE INDEX IF NOT EXISTS idx_ride_versions_designer_id 
  ON ride_versions(designer_id);

-- User engagement foreign keys
CREATE INDEX IF NOT EXISTS idx_user_ride_credits_ride_id 
  ON user_ride_credits(ride_id);

CREATE INDEX IF NOT EXISTS idx_reviews_moderated_by 
  ON reviews(moderated_by);

-- Moderation queue foreign keys
CREATE INDEX IF NOT EXISTS idx_content_submissions_reviewer_id 
  ON content_submissions(reviewer_id);

CREATE INDEX IF NOT EXISTS idx_content_submissions_original_submission_id 
  ON content_submissions(original_submission_id);

CREATE INDEX IF NOT EXISTS idx_reports_reviewed_by 
  ON reports(reviewed_by);

-- Profile lookup foreign keys
CREATE INDEX IF NOT EXISTS idx_profiles_location_id 
  ON profiles(location_id);

CREATE INDEX IF NOT EXISTS idx_profiles_home_park_id 
  ON profiles(home_park_id);