CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL,
  `email` varchar(100) NOT NULL,
  `password` varchar(255) NOT NULL,
  `balance` decimal(10,2) NOT NULL DEFAULT 0.00,
  `package_id` int(11) DEFAULT NULL,
  `package_expires_at` datetime DEFAULT NULL,
  `is_admin` tinyint(1) NOT NULL DEFAULT 0,
  `is_banned` tinyint(1) NOT NULL DEFAULT 0,
  `lang` varchar(2) NOT NULL DEFAULT 'tr',
  `theme` varchar(10) NOT NULL DEFAULT 'light',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `username` (`username`)
);

CREATE TABLE `packages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `price` decimal(10,2) NOT NULL,
  `duration` int(11) NOT NULL COMMENT 'in days',
  `daily_limit` int(11) NOT NULL,
  `monthly_limit` int(11) NOT NULL,
  `supports_envato` tinyint(1) NOT NULL DEFAULT 0,
  `supports_freepik` tinyint(1) NOT NULL DEFAULT 0,
  `status` tinyint(1) NOT NULL DEFAULT 1,
  PRIMARY KEY (`id`)
);

CREATE TABLE `downloads` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `platform` varchar(20) NOT NULL,
  `url` varchar(255) NOT NULL,
  `download_url` varchar(255) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `downloads_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
);

CREATE TABLE `payments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `payment_id` varchar(100) NOT NULL,
  `status` varchar(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `payments_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
);

CREATE TABLE `settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `key` varchar(50) NOT NULL,
  `value` text NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `key` (`key`)
);

INSERT INTO `settings` (`key`, `value`) VALUES
('site_title', 'StockPanel'),
('site_description', 'Dijital Medya İndirme Platformu'),
('api_key', 'YOUR_MARTISTOCK_API_KEY'),
('shopier_api_key', 'YOUR_SHOPIER_API_KEY'),
('shopier_api_secret', 'YOUR_SHOPIER_API_SECRET'),
('cooldown_time', '60'),
('site_logo', ''),
('site_favicon', ''),
('site_width', '1000'),
('theme_color', 'indigo'),
('bank_name', ''),
('bank_account_name', ''),
('bank_account_number', ''),
('bank_iban', ''),
('bank_branch', ''),
('meta_description', 'StockPanel - Dijital Medya İndirme Platformu'),
('meta_keywords', 'stock, download, freepik, envato elements'),
('additional_header_code', ''),
('additional_footer_code', ''),
('show_maskot', '1'),
('show_powered_by', '1'),
('license_type', 'free'),
('license_key', '');

CREATE TABLE `pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `slug` varchar(100) NOT NULL,
  `content` text NOT NULL,
  `is_visible` tinyint(1) NOT NULL DEFAULT 1,
  `show_in_sidebar` tinyint(1) NOT NULL DEFAULT 1,
  `order` int(11) NOT NULL DEFAULT 0,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `slug` (`slug`)
);

INSERT INTO `pages` (`title`, `slug`, `content`, `is_visible`, `show_in_sidebar`, `order`) VALUES
('Hakkımızda', 'hakkimizda', '<h1>Hakkımızda</h1><p>Bu sayfa site hakkında bilgiler içerir.</p>', 1, 1, 1),
('Yardım', 'yardim', '<h1>Yardım</h1><p>Yardım ve destek bilgileri.</p>', 1, 1, 2),
('Şartlar ve Koşullar', 'sartlar-ve-kosullar', '<h1>Şartlar ve Koşullar</h1><p>Site kullanım şartları ve koşulları.</p>', 1, 0, 3);