-- Instagram Unfollower Pro - Veritabanı Şeması
-- cPanel MySQL/MariaDB için

-- Versiyonlar tablosu
CREATE TABLE IF NOT EXISTS `app_versions` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `version` VARCHAR(20) NOT NULL,
  `download_url` TEXT NOT NULL,
  `changelog` TEXT,
  `is_mandatory` TINYINT(1) DEFAULT 0,
  `release_date` DATE NOT NULL,
  `is_active` TINYINT(1) DEFAULT 1,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `version` (`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Lisanslar tablosu
CREATE TABLE IF NOT EXISTS `licenses` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `license_key` VARCHAR(100) NOT NULL,
  `license_type` VARCHAR(50) DEFAULT 'standard',
  `expires_at` DATETIME NULL,
  `max_activations` INT(11) DEFAULT 1,
  `is_active` TINYINT(1) DEFAULT 1,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `license_key` (`license_key`),
  KEY `is_active` (`is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Lisans aktivasyonları tablosu
CREATE TABLE IF NOT EXISTS `license_activations` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `license_id` INT(11) NOT NULL,
  `machine_id` VARCHAR(64) NOT NULL,
  `activated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `deactivated_at` TIMESTAMP NULL,
  `is_active` TINYINT(1) DEFAULT 1,
  PRIMARY KEY (`id`),
  KEY `license_id` (`license_id`),
  KEY `machine_id` (`machine_id`),
  KEY `is_active` (`is_active`),
  UNIQUE KEY `license_machine` (`license_id`, `machine_id`, `is_active`),
  FOREIGN KEY (`license_id`) REFERENCES `licenses`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Örnek veri ekleme
-- Versiyon örneği
INSERT INTO `app_versions` (`version`, `download_url`, `changelog`, `is_mandatory`, `release_date`) 
VALUES (
  '1.0.1',
  'https://example.com/downloads/InstagramUnfollowerPro_1.0.1.zip',
  'Yeni özellikler:\n- Güncelleme mekanizması\n- Lisans kontrolü\n- Performans iyileştirmeleri',
  0,
  '2025-01-15'
);

-- Lisans örneği (test için)
INSERT INTO `licenses` (`license_key`, `license_type`, `expires_at`, `max_activations`) 
VALUES (
  'TEST-XXXX-XXXX-XXXX',
  'premium',
  '2025-12-31 23:59:59',
  3
);

