CREATE TABLE IF NOT EXISTS `review_codes` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `code` varchar(16) NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `listing_id` int(10) unsigned DEFAULT NULL,
  `credit_amount` decimal(10,2) DEFAULT 0.00,
  `used` tinyint(1) NOT NULL DEFAULT 0,
  `expires_at` datetime NOT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_code` (`code`),
  KEY `idx_user_id` (`user_id`),
  KEY `idx_used_expires` (`used`, `expires_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
