CREATE TABLE IF NOT EXISTS admins (
  id INT AUTO_INCREMENT PRIMARY KEY,
  nome VARCHAR(120) NOT NULL,
  email VARCHAR(160) NOT NULL UNIQUE,
  senha VARCHAR(255) NOT NULL,
  criado_em TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS devices (
  id INT AUTO_INCREMENT PRIMARY KEY,
  ip VARCHAR(45) NOT NULL UNIQUE,
  hostname VARCHAR(160) NULL,
  status ENUM('online','offline') DEFAULT 'offline',
  last_seen DATETIME NULL,
  atualizado_em TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS events (
  id INT AUTO_INCREMENT PRIMARY KEY,
  device_ip VARCHAR(45) NOT NULL,
  event_type ENUM('online','offline') NOT NULL,
  message VARCHAR(255) NULL,
  criado_em TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT IGNORE INTO admins (nome, email, senha)
VALUES ('Administrador webTHI', 'admin@webthi.com.br', '$2a$10$mZ1JpH2RwOD1h83KJ8wG4.wY1IGYHqg29qXvUfY0mQ8hj43DQk39e');
-- Senha: 123456
