--
-- Host: localhost    Database: pinrepair
-- ------------------------------------------------------


--
-- Table structure for table `debug_config`
--

CREATE TABLE `debug_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `is_enabled` tinyint(1) DEFAULT 0,
  `log_level` enum('error','warning','info','debug') DEFAULT 'error',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `errors`
--

CREATE TABLE `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;

--
-- Table structure for table `notification_queue`
--

CREATE TABLE `notification_queue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `error_id` int(11) NOT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `processed_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_error` (`error_id`),
  CONSTRAINT `notification_queue_ibfk_1` FOREIGN KEY (`error_id`) REFERENCES `errors` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Table structure for table `pinballs`
--

CREATE TABLE `pinballs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `manufacturer` varchar(255) NOT NULL,
  `year` int(11) DEFAULT NULL,
  `thumbnail` varchar(255) DEFAULT NULL,
  `group_id` char(1) NOT NULL DEFAULT 'A' CHECK (`group_id` in ('A','B','C','D','E','F','G','H','I','J')),
  `status` enum('active','inactive') DEFAULT 'active',
  `error_count` int(11) DEFAULT 0,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;



