-- =========================
-- Użytkownicy
-- =========================
CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT UNIQUE NOT NULL,
    password TEXT NOT NULL,
    email TEXT,
    full_name TEXT,
    active INTEGER DEFAULT 1,
    max_connections INTEGER DEFAULT 1,
    expire_date INTEGER,
    allowed_ips TEXT,
    allowed_ua TEXT,
    packages TEXT,
    created_at INTEGER,
    updated_at INTEGER
);

-- =========================
-- Sesje użytkowników
-- =========================
CREATE TABLE user_sessions (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id INTEGER,
    ip TEXT,
    user_agent TEXT,
    login_time INTEGER,
    last_activity INTEGER
);

-- =========================
-- Kategorie
-- =========================
CREATE TABLE live_categories (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
CREATE TABLE vod_categories (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
CREATE TABLE series_categories (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);

-- =========================
-- Kanały Live
-- =========================
CREATE TABLE live_channels (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    category_id INTEGER,
    url TEXT,
    thumbnail TEXT,
    status TEXT DEFAULT 'offline',
    quality TEXT,
    added_at INTEGER
);

-- =========================
-- VOD
-- =========================
CREATE TABLE vod (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT,
    category_id INTEGER,
    year INTEGER,
    duration TEXT,
    description TEXT,
    url TEXT,
    poster TEXT,
    added_at INTEGER
);

-- =========================
-- Seriale
-- =========================
CREATE TABLE series (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT,
    category_id INTEGER,
    seasons INTEGER,
    description TEXT,
    poster TEXT,
    added_at INTEGER
);

-- =========================
-- Pakiety
-- =========================
CREATE TABLE packages (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    description TEXT
);
CREATE TABLE package_channels (
    package_id INTEGER,
    channel_id INTEGER
);
CREATE TABLE package_vod (
    package_id INTEGER,
    vod_id INTEGER
);
CREATE TABLE package_series (
    package_id INTEGER,
    series_id INTEGER
);

-- =========================
-- Logi
-- =========================
CREATE TABLE admin_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    admin_id INTEGER,
    action TEXT,
    details TEXT,
    ip TEXT,
    created_at INTEGER
);
CREATE TABLE user_logs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id INTEGER,
    action TEXT,
    details TEXT,
    ip TEXT,
    created_at INTEGER
);
