-- Script para criar o banco de dados e as tabelas

CREATE DATABASE IF NOT EXISTS rengoku_recepcao CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

USE rengoku_recepcao;

-- Tabela de usuários
CREATE TABLE IF NOT EXISTS `users` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `username` VARCHAR(50) NOT NULL UNIQUE,
  `password` VARCHAR(255) NOT NULL,
  `role` ENUM('admin', 'receptionist') NOT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

-- Tabela de visitantes
CREATE TABLE IF NOT EXISTS `visitors` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `full_name` VARCHAR(255) NOT NULL,
  `document_id` VARCHAR(50) DEFAULT NULL,
  `check_in` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `check_out` TIMESTAMP NULL DEFAULT NULL,
  `destination` VARCHAR(255) NOT NULL,
  `registered_by` INT NOT NULL,
  FOREIGN KEY (`registered_by`) REFERENCES `users`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB;

-- Inserir usuário administrador padrão
-- Senha para 'admin' e 'recepcionista' é '123456' (deve ser alterada)
INSERT INTO `users` (`username`, `password`, `role`) VALUES ('admin', '$2b$12$ib3lQzssNNo6Uc79EF/wke3yHakUTTDoKMwFMU49IOgo55LV9jfXW', 'admin');

-- Inserir usuário recepcionista padrão

INSERT INTO `users` (`username`, `password`, `role`) VALUES ('recepcionista', '$2b$12$ib3lQzssNNo6Uc79EF/wke3yHakUTTDoKMwFMU49IOgo55LV9jfXW', 'receptionist');
