-- Table des tokens FCM par appareil / utilisateur
CREATE TABLE IF NOT EXISTS babi_push_tokens (
    id         INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id    INT UNSIGNED NOT NULL,
    token      VARCHAR(255) NOT NULL,
    platform   ENUM('android','ios','web') NOT NULL DEFAULT 'android',
    created_at DATETIME NOT NULL DEFAULT NOW(),
    updated_at DATETIME NOT NULL DEFAULT NOW(),
    UNIQUE KEY uq_token (token),
    INDEX idx_user (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Table des notifications envoyées (historique optionnel)
CREATE TABLE IF NOT EXISTS babi_notifications (
    id         INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id    INT UNSIGNED NULL COMMENT 'NULL = broadcast',
    type       ENUM('order_status','promo','alert','new_order') NOT NULL,
    title      VARCHAR(255) NOT NULL,
    body       TEXT NOT NULL,
    data       JSON NULL,
    sent_at    DATETIME NOT NULL DEFAULT NOW(),
    INDEX idx_user (user_id),
    INDEX idx_type (type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
