-- NexFusion Advanced License Server Schema

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

CREATE TABLE IF NOT EXISTS `nf_licenses` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `license_key` varchar(32) NOT NULL,
  `type` enum('trial','basic','pro','enterprise') NOT NULL DEFAULT 'basic',
  `domain` varchar(255) DEFAULT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `installation_id` varchar(64) DEFAULT NULL,
  `features` json DEFAULT NULL,
  `issued_at` int(11) NOT NULL,
  `expires_at` int(11) DEFAULT NULL,
  `is_lifetime` tinyint(1) NOT NULL DEFAULT 0,
  `status` enum('active','suspended','expired') NOT NULL DEFAULT 'active',
  `last_check` datetime DEFAULT NULL,
  `notes` text DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `license_key` (`license_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `nf_license_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `license_key` varchar(32) DEFAULT NULL,
  `domain` varchar(255) DEFAULT NULL,
  `installation_id` varchar(64) DEFAULT NULL,
  `ip` varchar(45) NOT NULL,
  `result` varchar(30) NOT NULL,
  `version` varchar(20) DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_license` (`license_key`),
  KEY `idx_time` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

COMMIT;
