-- Schema MySQL (produção / cPanel) — Angelina
-- Áudio bruto NUNCA é armazenado; só transcript final + ata.

CREATE TABLE IF NOT EXISTS usuarios (
    id         INT AUTO_INCREMENT PRIMARY KEY,
    nome       VARCHAR(120)  NOT NULL,
    email      VARCHAR(190)  NOT NULL UNIQUE,
    senha_hash VARCHAR(255)  NOT NULL,
    criado_em  TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS tokens (
    id         INT AUTO_INCREMENT PRIMARY KEY,
    usuario_id INT           NOT NULL,
    token      CHAR(64)      NOT NULL UNIQUE,
    criado_em  TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS reunioes (
    id               INT AUTO_INCREMENT PRIMARY KEY,
    usuario_id       INT           NOT NULL,
    titulo           VARCHAR(200)  NOT NULL,
    data_reuniao     DATE          NOT NULL,
    duracao_segundos INT           NOT NULL DEFAULT 0,
    criado_em        TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (usuario_id) REFERENCES usuarios(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS transcripts (
    id           INT AUTO_INCREMENT PRIMARY KEY,
    reuniao_id   INT           NOT NULL,
    conteudo_json LONGTEXT      NOT NULL,
    criado_em    TIMESTAMP      NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (reuniao_id) REFERENCES reunioes(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE IF NOT EXISTS atas (
    id            INT AUTO_INCREMENT PRIMARY KEY,
    reuniao_id    INT           NOT NULL,
    template_usado VARCHAR(50)   NOT NULL,
    conteudo      LONGTEXT      NOT NULL,
    criado_em     TIMESTAMP     NOT NULL DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (reuniao_id) REFERENCES reunioes(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
