CREATE TABLE IF NOT EXISTS `focus_sessions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `task_name` varchar(255) DEFAULT NULL,
  `duration_minutes` int(11) NOT NULL DEFAULT 25,
  `created_at` timestamp DEFAULT current_timestamp(),
  PRIMARY KEY (`id`)
);

DROP TABLE IF EXISTS `gamification_profiles`;
DROP TABLE IF EXISTS `gamification_badges`;
DROP TABLE IF EXISTS `user_badges`;
DROP TABLE IF EXISTS `badges`;
DROP TABLE IF EXISTS `user_xp`;

CREATE TABLE `user_xp` (
  `user_id` int(11) NOT NULL PRIMARY KEY,
  `xp_points` int(11) NOT NULL DEFAULT 0,
  `level` int(11) NOT NULL DEFAULT 1,
  `last_gain_at` datetime NOT NULL DEFAULT current_timestamp()
);

CREATE TABLE `badges` (
  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(100) NOT NULL,
  `icon` varchar(50) NOT NULL,
  `condition_type` varchar(50) NOT NULL,
  `condition_value` int(11) NOT NULL
);

CREATE TABLE `user_badges` (
  `user_id` int(11) NOT NULL,
  `badge_id` int(11) NOT NULL,
  `earned_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`user_id`, `badge_id`)
);

-- Basic starting badges
INSERT INTO `badges` (`name`, `icon`, `condition_type`, `condition_value`) VALUES
('مقاتل المهام', 'fa-solid fa-list-check', 'task_completed', 50),
('منضبط', 'fa-solid fa-fire', 'habit_done', 7),
('صائم دهره', 'fa-solid fa-moon', 'fast_completed', 10),
('مستثمر', 'fa-solid fa-money-bill-trend-up', 'finance_logged', 10);
