-- u00d6deme tablosu
CREATE TABLE IF NOT EXISTS `payments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `payment_id` varchar(100) NOT NULL,
  `user_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `payment_method` varchar(50) NOT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'pending',
  `transaction_id` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  `updated_by` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `payment_id` (`payment_id`),
  KEY `status` (`status`),
  KEY `payment_method` (`payment_method`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- u00d6deme makbuzlaru0131 tablosu (banka havalesi iu00e7in)
CREATE TABLE IF NOT EXISTS `payment_receipts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `payment_id` int(11) NOT NULL,
  `sender_name` varchar(255) NOT NULL,
  `transfer_date` date NOT NULL,
  `receipt_file` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `payment_id` (`payment_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Bakiye iu015flemleri tablosu
CREATE TABLE IF NOT EXISTS `balance_transactions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `description` text DEFAULT NULL,
  `transaction_type` varchar(50) NOT NULL,
  `related_id` int(11) DEFAULT NULL,
  `created_by` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `transaction_type` (`transaction_type`),
  KEY `related_id` (`related_id`),
  KEY `created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- Kullanu0131cu0131 tablosuna bakiye alanu0131 ekleme
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `balance` decimal(10,2) NOT NULL DEFAULT '0.00' AFTER `email`;

-- Sunucu u00f6demeleri tablosu
CREATE TABLE IF NOT EXISTS `server_payments` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `server_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `payment_period` varchar(20) NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'active',
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  KEY `server_id` (`server_id`),
  KEY `status` (`status`),
  KEY `end_date` (`end_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- u00d6deme ayarlaru0131 tablosu
CREATE TABLE IF NOT EXISTS `payment_settings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `setting_key` varchar(100) NOT NULL,
  `setting_value` text NOT NULL,
  `description` text DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `setting_key` (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

-- u00d6deme ayarlaru0131 iu00e7in varsayu0131lan deu011ferler
INSERT IGNORE INTO `payment_settings` (`setting_key`, `setting_value`, `description`, `updated_at`) VALUES
('bank_account_details', '{"bank_name":"XYZ Bank","account_name":"TeamSpeak Panel","iban":"TR00 0000 0000 0000 0000 0000 00","branch_code":"123"}', 'Banka hesap bilgileri', NOW()),
('payment_methods', '{"credit_card":true,"bank_transfer":true}', 'Aktif u00f6deme yu00f6ntemleri', NOW()),
('min_payment_amount', '10', 'Minimum u00f6deme tutaru0131', NOW()),
('max_payment_amount', '1000', 'Maksimum u00f6deme tutaru0131', NOW()),
('currency', 'TL', 'Para birimi', NOW()),
('payment_notification_email', 'admin@example.com', 'u00d6deme bildirimleri iu00e7in e-posta adresi', NOW());
