-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Jun 30, 2025 at 05:10 PM
-- Server version: 8.4.3
-- PHP Version: 8.3.16

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `gestao_docs`
--

-- --------------------------------------------------------

--
-- Table structure for table `configuracoes_frequencia_status`
--

CREATE TABLE `configuracoes_frequencia_status` (
  `id` int NOT NULL,
  `status_documento` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `frequencia_envio` enum('unico','diario','cada_x_dias') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unico',
  `intervalo_dias` int DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `configuracoes_sistema`
--

CREATE TABLE `configuracoes_sistema` (
  `id` int NOT NULL,
  `logo_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `favicon_url` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cor_primaria` varchar(7) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cor_secundaria` varchar(7) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `smtp_host` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `smtp_port` int DEFAULT NULL,
  `smtp_username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `smtp_password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `smtp_encryption` enum('tls','ssl','none') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `url_webhook_global` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `webhook_ativo` tinyint(1) NOT NULL DEFAULT '0',
  `texto_logo` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `estilo_texto_logo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `hora_envio_notificacoes` varchar(5) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `webhook_delay_ms` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Inserir configuração inicial do sistema
INSERT INTO `configuracoes_sistema` (`id`) VALUES (1);

-- --------------------------------------------------------

--
-- Table structure for table `contadores`
--

CREATE TABLE `contadores` (
  `id` int NOT NULL,
  `nome` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `telefone` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `data_cadastro` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ativo` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `documentos`
--

CREATE TABLE `documentos` (
  `id` int NOT NULL,
  `id_empresa` int NOT NULL,
  `id_tipo_documento` int NOT NULL,
  `nome_documento` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `data_emissao` date NOT NULL,
  `data_vencimento` date NOT NULL,
  `prazo_aviso_dias` int NOT NULL,
  `caminho_arquivo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `link_documento` varchar(500) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `emitido_por_contador` tinyint(1) NOT NULL DEFAULT '0',
  `observacoes` text COLLATE utf8mb4_unicode_ci,
  `data_upload` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `status_documento` enum('Válido','Próximo do Vencimento','Vencido','Não Aplicável') COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `documento_destinatarios_notificacao`
--

CREATE TABLE `documento_destinatarios_notificacao` (
  `id` int NOT NULL,
  `id_documento` int NOT NULL,
  `nome_destinatario` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email_destinatario` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `telefone_destinatario` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `empresas`
--

CREATE TABLE `empresas` (
  `id` int NOT NULL,
  `nome_fantasia` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `razao_social` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `cnpj` varchar(18) COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_contador_principal` int DEFAULT NULL,
  `data_cadastro` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ativo` tinyint(1) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `links_compartilhamento`
--

CREATE TABLE `links_compartilhamento` (
  `id` int NOT NULL,
  `uuid` varchar(36) COLLATE utf8mb4_unicode_ci NOT NULL,
  `id_empresa` int NOT NULL,
  `id_tipo_documento` int DEFAULT NULL,
  `data_criacao` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `data_expiracao` datetime DEFAULT NULL,
  `ativo` tinyint(1) NOT NULL DEFAULT '1',
  CONSTRAINT `fk_tipo_documento` FOREIGN KEY (`id_tipo_documento`) REFERENCES `tipos_documentos`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `log_envio_notificacoes`
--

CREATE TABLE `log_envio_notificacoes` (
  `id` int NOT NULL,
  `id_documento` int NOT NULL,
  `status_documento` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `data_envio` datetime NOT NULL,
  `destinatario` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `templates_email`
--

CREATE TABLE `templates_email` (
  `id` int NOT NULL,
  `nome_template` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `assunto` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `corpo_html` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `data_criacao` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ativo` tinyint(1) NOT NULL DEFAULT '1',
  `status_destino` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Válido'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `tipos_documentos`
--

CREATE TABLE `tipos_documentos` (
  `id` int NOT NULL,
  `nome_tipo` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `usuarios`
--

CREATE TABLE `usuarios` (
  `id` int NOT NULL,
  `nome` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `senha` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `data_cadastro` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `ativo` tinyint(1) NOT NULL DEFAULT '1',
  `perfil` enum('Administrador','Usuário Comum') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Administrador'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `usuarios`
--

INSERT INTO `usuarios` (`id`, `nome`, `email`, `senha`, `data_cadastro`, `ativo`, `perfil`) VALUES
(1, 'William', 'william@istar.com.br', '$2y$10$e1vU5ePJDz3EIWxR8JQGL.bwGs5YZmzDWUSwG.8gX/6cfjo2v1YzK', '2025-06-27 12:50:16', 1, 'Administrador'),
(2, 'Usuário Comum', 'usuario@gestaodocs.com', '$2y$10$sDNrd6yZs0qC/O3fJZleI.5982K8Lgn.btQcV7WMQrQbpb3mbzRci', '2025-06-27 12:50:16', 0, 'Administrador'),
(3, 'teste', 'teste@teste.com', '$2y$10$lReT0fVyIiABOCI1nQ5Wy.KWfphcw/VvG5LA6vyLDbv4S7ty.fkM.', '2025-06-30 10:18:03', 1, 'Usuário Comum');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `configuracoes_frequencia_status`
--
ALTER TABLE `configuracoes_frequencia_status`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `configuracoes_sistema`
--
ALTER TABLE `configuracoes_sistema`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `contadores`
--
ALTER TABLE `contadores`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `email` (`email`);

--
-- Indexes for table `documentos`
--
ALTER TABLE `documentos`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_empresa` (`id_empresa`),
  ADD KEY `id_tipo_documento` (`id_tipo_documento`);

--
-- Indexes for table `documento_destinatarios_notificacao`
--
ALTER TABLE `documento_destinatarios_notificacao`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_documento` (`id_documento`);

--
-- Indexes for table `empresas`
--
ALTER TABLE `empresas`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `cnpj` (`cnpj`),
  ADD KEY `id_contador_principal` (`id_contador_principal`);

--
-- Indexes for table `links_compartilhamento`
--
ALTER TABLE `links_compartilhamento`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uuid` (`uuid`),
  ADD KEY `id_empresa` (`id_empresa`);

--
-- Indexes for table `log_envio_notificacoes`
--
ALTER TABLE `log_envio_notificacoes`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `templates_email`
--
ALTER TABLE `templates_email`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `nome_template` (`nome_template`);

--
-- Indexes for table `tipos_documentos`
--
ALTER TABLE `tipos_documentos`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `nome_tipo` (`nome_tipo`);

--
-- Indexes for table `usuarios`
--
ALTER TABLE `usuarios`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `email` (`email`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `configuracoes_frequencia_status`
--
ALTER TABLE `configuracoes_frequencia_status`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `configuracoes_sistema`
--
ALTER TABLE `configuracoes_sistema`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `contadores`
--
ALTER TABLE `contadores`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `documentos`
--
ALTER TABLE `documentos`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `documento_destinatarios_notificacao`
--
ALTER TABLE `documento_destinatarios_notificacao`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `empresas`
--
ALTER TABLE `empresas`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `links_compartilhamento`
--
ALTER TABLE `links_compartilhamento`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `log_envio_notificacoes`
--
ALTER TABLE `log_envio_notificacoes`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `templates_email`
--
ALTER TABLE `templates_email`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `tipos_documentos`
--
ALTER TABLE `tipos_documentos`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `usuarios`
--
ALTER TABLE `usuarios`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `documentos`
--
ALTER TABLE `documentos`
  ADD CONSTRAINT `documentos_ibfk_1` FOREIGN KEY (`id_empresa`) REFERENCES `empresas` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `documentos_ibfk_2` FOREIGN KEY (`id_tipo_documento`) REFERENCES `tipos_documentos` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `documento_destinatarios_notificacao`
--
ALTER TABLE `documento_destinatarios_notificacao`
  ADD CONSTRAINT `documento_destinatarios_notificacao_ibfk_1` FOREIGN KEY (`id_documento`) REFERENCES `documentos` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `empresas`
--
ALTER TABLE `empresas`
  ADD CONSTRAINT `empresas_ibfk_1` FOREIGN KEY (`id_contador_principal`) REFERENCES `contadores` (`id`) ON DELETE SET NULL;

--
-- Constraints for table `links_compartilhamento`
--
ALTER TABLE `links_compartilhamento`
  ADD CONSTRAINT `links_compartilhamento_ibfk_1` FOREIGN KEY (`id_empresa`) REFERENCES `empresas` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
