USE prefeitura_resolve;

CREATE TABLE IF NOT EXISTS api_tokens (
    id INT AUTO_INCREMENT PRIMARY KEY,
    nome VARCHAR(100) NOT NULL,
    token VARCHAR(255) NOT NULL UNIQUE,
    ativo TINYINT(1) NOT NULL DEFAULT 1,
    criado_em DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO api_tokens (nome, token, ativo)
SELECT 'Chatbot WhatsApp', 'CHANGE_ME_WHATSAPP_TOKEN', 1
WHERE NOT EXISTS (
    SELECT 1 FROM api_tokens WHERE token = 'CHANGE_ME_WHATSAPP_TOKEN'
);
