-- Create appointments table (matches schema.sql definition)

CREATE TABLE `appointments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) DEFAULT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `phone` varchar(50) DEFAULT NULL,
  `topic` varchar(255) NOT NULL,
  `details` text DEFAULT NULL,
  `preferred_datetime` datetime DEFAULT NULL,
  `timezone` varchar(64) DEFAULT NULL,
  `duration_minutes` int(11) DEFAULT NULL,
  `amount` decimal(10,2) DEFAULT NULL,
  `currency` varchar(3) DEFAULT NULL,
  `payment_status` enum('free','pending','paid','failed') NOT NULL DEFAULT 'free',
  `payment_gateway` enum('paystack','square') DEFAULT NULL,
  `payment_reference` varchar(100) DEFAULT NULL,
  `paid_at` datetime DEFAULT NULL,
  `status` enum('requested','accepted','scheduled','cancelled','completed') NOT NULL DEFAULT 'requested',
  `zoom_meeting_id` varchar(100) DEFAULT NULL,
  `zoom_join_url` varchar(255) DEFAULT NULL,
  `zoom_start_time` datetime DEFAULT NULL,
  `reminder_sent_at` datetime DEFAULT NULL,
  `admin_notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_status` (`status`),
  KEY `idx_preferred_datetime` (`preferred_datetime`),
  CONSTRAINT `fk_appointments_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
