-- config.php içindeki import_prefix değerine göre tabloları oluşturun.
-- Varsayılan prefix: kai_

CREATE TABLE IF NOT EXISTS `kai_import_batches` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `batch_code` varchar(64) NOT NULL,
  `source_urls_json` longtext,
  `status` varchar(30) NOT NULL,
  `total_products` int NOT NULL DEFAULT 0,
  `processed_products` int NOT NULL DEFAULT 0,
  `logs` longtext,
  `created_at` datetime NOT NULL,
  `started_at` datetime DEFAULT NULL,
  `finished_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `batch_code` (`batch_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `kai_import_products` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `batch_id` int unsigned NOT NULL,
  `source_url` varchar(500) NOT NULL,
  `source_category_url` varchar(500) DEFAULT NULL,
  `sku` varchar(191) DEFAULT NULL,
  `name` varchar(255) NOT NULL,
  `description_html` longtext,
  `description_text` longtext,
  `price` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `special_price` decimal(15,4) NOT NULL DEFAULT 0.0000,
  `main_image` varchar(500) DEFAULT NULL,
  `additional_images_json` longtext,
  `categories_json` longtext,
  `seo_keyword` varchar(255) DEFAULT NULL,
  `stock_status` tinyint(1) NOT NULL DEFAULT 1,
  `meta_title` varchar(255) DEFAULT NULL,
  `meta_description` varchar(255) DEFAULT NULL,
  `opencart_product_id` int DEFAULT NULL,
  `hash_key` varchar(32) NOT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'pending',
  `notes` text,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `batch_id` (`batch_id`),
  KEY `status` (`status`),
  KEY `hash_key` (`hash_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
