CREATE TABLE IF NOT EXISTS `errors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pinball_id` int(11) NOT NULL,
  `reporter_id` int(11) NOT NULL,
  `technician_id` int(11) DEFAULT NULL,
  `description` text NOT NULL,
  `media_path` varchar(255) DEFAULT NULL,
  `is_urgent` tinyint(1) DEFAULT 0,
  `status` enum('pending','resolved') DEFAULT 'pending',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `resolved_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `pinball_id` (`pinball_id`),
  KEY `reporter_id` (`reporter_id`),
  KEY `technician_id` (`technician_id`),
  CONSTRAINT `errors_ibfk_1` FOREIGN KEY (`pinball_id`) REFERENCES `pinballs` (`id`) ON DELETE CASCADE,
  CONSTRAINT `errors_ibfk_2` FOREIGN KEY (`reporter_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `errors_ibfk_3` FOREIGN KEY (`technician_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
