-- Tnet Time — cPanel / shared hosting import
-- 1) Create a MySQL database in cPanel (MySQL Databases)
-- 2) Open phpMyAdmin, select YOUR database (not import this file globally)
-- 3) Import this file — do NOT use database.sql (CREATE DATABASE fails on shared hosting)

CREATE TABLE IF NOT EXISTS devices (
    id INT AUTO_INCREMENT PRIMARY KEY,
    fcm_token VARCHAR(512) NOT NULL UNIQUE,
    language VARCHAR(10) DEFAULT 'en',
    app_version VARCHAR(20) DEFAULT NULL,
    device_model VARCHAR(100) DEFAULT NULL,
    os_version VARCHAR(20) DEFAULT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    last_seen TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    is_active TINYINT(1) DEFAULT 1,
    INDEX idx_last_seen (last_seen),
    INDEX idx_language (language)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS push_logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    body TEXT NOT NULL,
    sent_count INT DEFAULT 0,
    failed_count INT DEFAULT 0,
    target_language VARCHAR(10) DEFAULT 'all',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
