-- Create admin_onboarding_progress table
CREATE TABLE `admin_onboarding_progress` (
	`id` int AUTO_INCREMENT NOT NULL,
	`adminId` int NOT NULL,
	`currentStep` enum('welcome','role_assignment','permission_training','security_training','device_registration','completion') NOT NULL DEFAULT 'welcome',
	`completedSteps` json NOT NULL DEFAULT (json_array()),
	`roleAssigned` enum('super_admin','admin','moderator','finance_team','developer','support_lead'),
	`permissionsAcknowledged` tinyint NOT NULL DEFAULT 0,
	`securityTrainingCompleted` tinyint NOT NULL DEFAULT 0,
	`securityQuizScore` int,
	`deviceRegistered` tinyint NOT NULL DEFAULT 0,
	`deviceName` varchar(255),
	`deviceBrowser` varchar(100),
	`deviceOs` varchar(100),
	`deviceIpAddress` varchar(64),
	`startedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`completedAt` timestamp,
	`lastActivityAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `admin_onboarding_progress_id` PRIMARY KEY (`id`),
	INDEX `idx_admin_onboarding_adminId` (`adminId`),
	INDEX `idx_admin_onboarding_currentStep` (`currentStep`),
	INDEX `idx_admin_onboarding_completedAt` (`completedAt`)
);

-- Create admin_profiles table
CREATE TABLE `admin_profiles` (
	`id` int AUTO_INCREMENT NOT NULL,
	`adminId` int NOT NULL,
	`avatarUrl` text,
	`phoneNumber` varchar(20),
	`timezone` varchar(64) NOT NULL DEFAULT 'UTC',
	`language` varchar(10) NOT NULL DEFAULT 'en',
	`notificationPreferences` json,
	`twoFactorEnabled` tinyint NOT NULL DEFAULT 0,
	`twoFactorSecret` varchar(255),
	`backupCodes` json,
	`lastProfileUpdateAt` timestamp,
	`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	CONSTRAINT `admin_profiles_id` PRIMARY KEY (`id`),
	INDEX `idx_admin_profiles_adminId` (`adminId`)
);

-- Create admin_device_registrations table
CREATE TABLE `admin_device_registrations` (
	`id` int AUTO_INCREMENT NOT NULL,
	`adminId` int NOT NULL,
	`deviceId` varchar(255) NOT NULL,
	`deviceName` varchar(255) NOT NULL,
	`browser` varchar(100) NOT NULL,
	`os` varchar(100) NOT NULL,
	`ipAddress` varchar(64) NOT NULL,
	`userAgent` text,
	`isActive` tinyint NOT NULL DEFAULT 1,
	`lastUsedAt` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
	`registeredAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `admin_device_registrations_id` PRIMARY KEY (`id`),
	INDEX `idx_admin_devices_adminId` (`adminId`),
	INDEX `idx_admin_devices_deviceId` (`deviceId`)
);

-- Create onboarding_analytics table
CREATE TABLE `onboarding_analytics` (
	`id` int AUTO_INCREMENT NOT NULL,
	`totalAdmins` int NOT NULL DEFAULT 0,
	`completedOnboardings` int NOT NULL DEFAULT 0,
	`pendingOnboardings` int NOT NULL DEFAULT 0,
	`averageCompletionTimeMinutes` int,
	`averageQuizScore` decimal(5,2),
	`stepCompletionRates` json,
	`roleDistribution` json,
	`dateRecorded` varchar(10) NOT NULL,
	`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	CONSTRAINT `onboarding_analytics_id` PRIMARY KEY (`id`),
	INDEX `idx_onboarding_analytics_date` (`dateRecorded`)
);
