-- أنواع المستخدمين وقوالب الصلاحيات (تُنشأ تلقائياً من user_types_core.php أيضاً)

CREATE TABLE IF NOT EXISTS `user_types` (
  `ID` INT NOT NULL AUTO_INCREMENT,
  `TypeName` VARCHAR(150) NOT NULL,
  `Notes` TEXT NULL,
  `IsActive` TINYINT(1) NOT NULL DEFAULT 1,
  `CreatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `UpdatedAt` DATETIME NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `uk_user_type_name` (`TypeName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS `user_type_permissions` (
  `ID` INT NOT NULL AUTO_INCREMENT,
  `type_id` INT NOT NULL,
  `module_id` INT NOT NULL,
  `p_read` TINYINT(1) NOT NULL DEFAULT 0,
  `p_create` TINYINT(1) NOT NULL DEFAULT 0,
  `p_update` TINYINT(1) NOT NULL DEFAULT 0,
  `p_delete` TINYINT(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `uk_type_module` (`type_id`,`module_id`),
  KEY `idx_utp_type` (`type_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
