-- Basit ve Çalışan Kurulum
-- Copy-paste çalıştırın

CREATE TABLE IF NOT EXISTS `announcement_announcement_groups` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `announcement_id` INT NOT NULL,
    `group_id` INT NOT NULL,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY `unique_announcement_group` (`announcement_id`, `group_id`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `announcement_reads` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `announcement_id` INT NOT NULL,
    `client_uuid` VARCHAR(36) NOT NULL,
    `read_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_client_uuid` (`client_uuid`),
    INDEX `idx_announcement_id` (`announcement_id`),
    UNIQUE KEY `unique_announcement_client` (`announcement_id`, `client_uuid`)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `announcement_api_keys` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `key_name` VARCHAR(100) NOT NULL,
    `api_key` VARCHAR(255) NOT NULL UNIQUE,
    `is_active` BOOLEAN DEFAULT TRUE,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    `expires_at` TIMESTAMP NULL
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS `announcement_admin_users` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `username` VARCHAR(50) NOT NULL UNIQUE,
    `password` VARCHAR(255) NOT NULL,
    `email` VARCHAR(255),
    `is_active` BOOLEAN DEFAULT TRUE,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

INSERT IGNORE INTO `announcement_api_keys` (`key_name`, `api_key`) VALUES 
('default_client_key', 'ANNOUNCEMENT_API_KEY_2024_SECURE_TOKEN');

INSERT IGNORE INTO `announcement_admin_users` (`username`, `password`, `email`, `is_active`) VALUES 
('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin@company.com', TRUE);

SELECT '✅ Kurulum tamamlandı!' AS mesaj;
