CREATE TABLE IF NOT EXISTS licenses (
  id INT AUTO_INCREMENT PRIMARY KEY,
  license_id VARCHAR(80) NOT NULL UNIQUE,
  license_key TEXT NOT NULL,
  customer_email VARCHAR(190) DEFAULT NULL,
  customer_name VARCHAR(190) DEFAULT NULL,
  plan VARCHAR(80) NOT NULL DEFAULT 'pro',
  validity_minutes INT NOT NULL DEFAULT 0,
  max_devices INT NOT NULL DEFAULT 1,
  status ENUM('active','disabled','expired') NOT NULL DEFAULT 'active',
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  activated_at DATETIME DEFAULT NULL,
  expires_at DATETIME DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS license_devices (
  id INT AUTO_INCREMENT PRIMARY KEY,
  license_id VARCHAR(80) NOT NULL,
  device_id VARCHAR(190) NOT NULL,
  session_id VARCHAR(120) NOT NULL,
  activated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  last_check_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  UNIQUE KEY uniq_license_device (license_id, device_id),
  INDEX idx_license_id (license_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
