CREATE TABLE IF NOT EXISTS fare_settings (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  ride_type ENUM('okada','car') NOT NULL UNIQUE,

  base_fare DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  per_km_rate DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  per_minute_rate DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  minimum_fare DECIMAL(10,2) NOT NULL DEFAULT 0.00,

  platform_commission_percent DECIMAL(5,2) NOT NULL DEFAULT 18.50,
  active TINYINT(1) NOT NULL DEFAULT 1,

  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

INSERT INTO fare_settings (
  ride_type,
  base_fare,
  per_km_rate,
  per_minute_rate,
  minimum_fare,
  platform_commission_percent,
  active
) VALUES
('okada', 10.00, 2.50, 0.40, 15.00, 18.50, 1),
('car', 18.00, 4.50, 0.60, 25.00, 18.50, 1)
ON DUPLICATE KEY UPDATE
  base_fare = VALUES(base_fare),
  per_km_rate = VALUES(per_km_rate),
  per_minute_rate = VALUES(per_minute_rate),
  minimum_fare = VALUES(minimum_fare),
  platform_commission_percent = VALUES(platform_commission_percent),
  active = VALUES(active);

ALTER TABLE ride_requests
ADD COLUMN distance_km DECIMAL(10,2) NULL AFTER destination_lng,
ADD COLUMN estimated_minutes INT NULL AFTER distance_km,
ADD COLUMN platform_commission DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER final_fare,
ADD COLUMN partner_earning DECIMAL(10,2) NOT NULL DEFAULT 0.00 AFTER platform_commission;
