-- Schema SQLite (dev local) — equivalente ao MySQL.

CREATE TABLE IF NOT EXISTS usuarios (
    id         INTEGER PRIMARY KEY AUTOINCREMENT,
    nome       TEXT NOT NULL,
    email      TEXT NOT NULL UNIQUE,
    senha_hash TEXT NOT NULL,
    criado_em  TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS tokens (
    id         INTEGER PRIMARY KEY AUTOINCREMENT,
    usuario_id INTEGER NOT NULL REFERENCES usuarios(id) ON DELETE CASCADE,
    token      TEXT NOT NULL UNIQUE,
    criado_em  TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS reunioes (
    id               INTEGER PRIMARY KEY AUTOINCREMENT,
    usuario_id       INTEGER NOT NULL REFERENCES usuarios(id) ON DELETE CASCADE,
    titulo           TEXT NOT NULL,
    data_reuniao     TEXT NOT NULL,
    duracao_segundos INTEGER NOT NULL DEFAULT 0,
    criado_em        TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS transcripts (
    id            INTEGER PRIMARY KEY AUTOINCREMENT,
    reuniao_id    INTEGER NOT NULL REFERENCES reunioes(id) ON DELETE CASCADE,
    conteudo_json TEXT NOT NULL,
    criado_em     TEXT NOT NULL DEFAULT (datetime('now'))
);

CREATE TABLE IF NOT EXISTS atas (
    id             INTEGER PRIMARY KEY AUTOINCREMENT,
    reuniao_id     INTEGER NOT NULL REFERENCES reunioes(id) ON DELETE CASCADE,
    template_usado TEXT NOT NULL,
    conteudo       TEXT NOT NULL,
    criado_em      TEXT NOT NULL DEFAULT (datetime('now'))
);
