-- Eksik Tabloları Tamamla
-- Mevcut: announcement_groups, announcement_announcements
-- Eksik: announcement_clients, announcement_announcement_groups, announcement_reads, announcement_api_keys, announcement_admin_users

-- Client'lar tablosu
CREATE TABLE `announcement_clients` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `client_uuid` VARCHAR(36) NOT NULL UNIQUE,
    `pc_name` VARCHAR(255) NOT NULL,
    `user_name` VARCHAR(255) NOT NULL,
    `group_id` INT NOT NULL,
    `last_seen` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX `idx_client_uuid` (`client_uuid`),
    INDEX `idx_group_id` (`group_id`)
) ENGINE=InnoDB;

-- Duyuru-Grup ilişkileri tablosu
CREATE TABLE `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;

-- Okuma kayıtları tablosu
CREATE TABLE `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;

SELECT '✅ Eksik tablolar eklendi!' AS mesaj;
