CREATE TABLE IF NOT EXISTS `Users` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(255) NOT NULL,
  `email` VARCHAR(255) NOT NULL UNIQUE,
  `password` VARCHAR(255) NOT NULL,
  `role` ENUM('Admin', 'Student', 'Super Admin') NOT NULL,
  `gender` ENUM('Male', 'Female', 'Other'),
  `year` INT,
  `department` VARCHAR(255),
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS `Rooms` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `room_no` VARCHAR(50) NOT NULL,
  `block` VARCHAR(50),
  `capacity` INT NOT NULL,
  `occupied` INT DEFAULT 0,
  `type` VARCHAR(100),
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS `Allocations` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `student_id` INT NOT NULL,
  `room_id` INT NOT NULL,
  `allocation_date` DATE,
  `status` VARCHAR(100),
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (`student_id`) REFERENCES `Users`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`room_id`) REFERENCES `Rooms`(`id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `Requests` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `student_id` INT NOT NULL,
  `room_preference` VARCHAR(255),
  `approval_status` VARCHAR(100) DEFAULT 'Pending',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (`student_id`) REFERENCES `Users`(`id`) ON DELETE CASCADE
);