/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

CREATE DATABASE IF NOT EXISTS `lbodev_bd_2026_crmvenasabiertas` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */;
USE `lbodev_bd_2026_crmvenasabiertas`;

CREATE TABLE IF NOT EXISTS `activity_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `subject_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `subject_id` bigint unsigned NOT NULL,
  `causer_type` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `causer_id` bigint unsigned DEFAULT NULL,
  `event` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `properties` json DEFAULT NULL,
  `old_attributes` json DEFAULT NULL,
  `new_attributes` json DEFAULT NULL,
  `created_at` timestamp NOT NULL,
  PRIMARY KEY (`id`),
  KEY `activity_logs_subject_type_subject_id_index` (`subject_type`,`subject_id`),
  KEY `activity_logs_causer_type_causer_id_index` (`causer_type`,`causer_id`),
  KEY `activity_logs_event_index` (`event`),
  KEY `activity_logs_created_at_index` (`created_at`),
  KEY `activity_logs_tenant_id_index` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `activity_logs`;

CREATE TABLE IF NOT EXISTS `cache` (
  `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` mediumtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` int NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `cache`;
INSERT INTO `cache` (`key`, `value`, `expiration`) VALUES
	('kontract-cache-system_setting_max_job_attempts', 's:1:"3";', 1780870413),
	('kontract-cache-system_setting_queue_connection', 's:8:"database";', 1780690567),
	('kontract-cache-system_setting_use_queues_for_notifications', 's:1:"1";', 1781562023),
	('kontract-cache-whatsapp_last_send_', 'O:25:"Illuminate\\Support\\Carbon":3:{s:4:"date";s:26:"2026-04-27 14:34:18.632780";s:13:"timezone_type";i:3;s:8:"timezone";s:17:"America/Sao_Paulo";}', 1777313058),
	('kontract-cache-whatsapp_last_send_1', 'O:25:"Illuminate\\Support\\Carbon":3:{s:4:"date";s:26:"2026-06-06 12:31:18.644581";s:13:"timezone_type";i:3;s:8:"timezone";s:17:"America/Sao_Paulo";}', 1780761678);

CREATE TABLE IF NOT EXISTS `cache_locks` (
  `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `owner` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `expiration` int NOT NULL,
  PRIMARY KEY (`key`),
  KEY `cache_locks_expiration_index` (`expiration`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `cache_locks`;

CREATE TABLE IF NOT EXISTS `company_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned NOT NULL,
  `company_name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_document` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_address` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_number` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_complement` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_district` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_city` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_state` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_zip` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_website` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_description` text COLLATE utf8mb4_unicode_ci,
  `company_logo` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `whatsapp_enabled` tinyint(1) NOT NULL DEFAULT '0',
  `whatsapp_api_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `whatsapp_sender` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `whatsapp_api_url` text COLLATE utf8mb4_unicode_ci,
  `whatsapp_outbound_endpoint` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `company_settings_user_id_unique` (`user_id`),
  KEY `company_settings_tenant_id_index` (`tenant_id`),
  CONSTRAINT `company_settings_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `company_settings`;

CREATE TABLE IF NOT EXISTS `contracts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned NOT NULL,
  `contratada_id` bigint unsigned NOT NULL,
  `contratante_id` bigint unsigned DEFAULT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text COLLATE utf8mb4_unicode_ci,
  `amount` decimal(12,2) DEFAULT NULL,
  `contract_body` longtext COLLATE utf8mb4_unicode_ci,
  `status` enum('draft','awaiting_client_data','in_progress','awaiting_approval','approved','rejected','signed','pdf_sent','completed','cancelled','expired') COLLATE utf8mb4_unicode_ci DEFAULT 'draft',
  `access_token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token_expires_at` timestamp NULL DEFAULT NULL,
  `pdf_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `signed_at` timestamp NULL DEFAULT NULL,
  `signed_by_client` tinyint(1) NOT NULL DEFAULT '0',
  `cancelled_at` timestamp NULL DEFAULT NULL,
  `cancelled_by` bigint unsigned DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `validated_by` bigint unsigned DEFAULT NULL,
  `validated_at` timestamp NULL DEFAULT NULL,
  `history` json DEFAULT NULL,
  `phase_events` json DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `contracts_access_token_unique` (`access_token`),
  KEY `contracts_template_id_foreign` (`template_id`),
  KEY `contracts_cancelled_by_foreign` (`cancelled_by`),
  KEY `contracts_created_by_foreign` (`created_by`),
  KEY `contracts_validated_by_foreign` (`validated_by`),
  KEY `contracts_access_token_index` (`access_token`),
  KEY `contracts_created_at_index` (`created_at`),
  KEY `contracts_status_index` (`status`),
  KEY `contracts_user_id_index` (`user_id`),
  KEY `contracts_contratada_id_foreign` (`contratada_id`),
  KEY `contracts_contratante_id_foreign` (`contratante_id`),
  KEY `contracts_tenant_id_index` (`tenant_id`),
  CONSTRAINT `contracts_cancelled_by_foreign` FOREIGN KEY (`cancelled_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contracts_contratada_id_foreign` FOREIGN KEY (`contratada_id`) REFERENCES `contratadas` (`id`) ON DELETE CASCADE,
  CONSTRAINT `contracts_contratante_id_foreign` FOREIGN KEY (`contratante_id`) REFERENCES `contratantes` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contracts_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contracts_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `contract_templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contracts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `contracts_validated_by_foreign` FOREIGN KEY (`validated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contracts`;

CREATE TABLE IF NOT EXISTS `contract_approval_tokens` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `contract_id` bigint unsigned NOT NULL,
  `token` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `action_type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `expires_at` timestamp NOT NULL,
  `used` tinyint(1) NOT NULL DEFAULT '0',
  `used_at` timestamp NULL DEFAULT NULL,
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `contract_approval_tokens_token_unique` (`token`),
  KEY `contract_approval_tokens_contract_id_foreign` (`contract_id`),
  CONSTRAINT `contract_approval_tokens_contract_id_foreign` FOREIGN KEY (`contract_id`) REFERENCES `contracts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contract_approval_tokens`;

CREATE TABLE IF NOT EXISTS `contract_data` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `contract_id` bigint unsigned NOT NULL,
  `payload` json NOT NULL,
  `type` enum('client_update','admin_update') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'client_update',
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contract_data_updated_by_foreign` (`updated_by`),
  KEY `contract_data_contract_id_index` (`contract_id`),
  KEY `contract_data_user_id_index` (`user_id`),
  CONSTRAINT `contract_data_contract_id_foreign` FOREIGN KEY (`contract_id`) REFERENCES `contracts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `contract_data_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contract_data_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contract_data`;

CREATE TABLE IF NOT EXISTS `contract_status_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `contract_id` bigint unsigned NOT NULL,
  `old_status` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `new_status` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `changed_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contract_status_logs_contract_id_foreign` (`contract_id`),
  KEY `contract_status_logs_changed_by_foreign` (`changed_by`),
  KEY `contract_status_logs_user_id_index` (`user_id`),
  CONSTRAINT `contract_status_logs_changed_by_foreign` FOREIGN KEY (`changed_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contract_status_logs_contract_id_foreign` FOREIGN KEY (`contract_id`) REFERENCES `contracts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `contract_status_logs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contract_status_logs`;

CREATE TABLE IF NOT EXISTS `contract_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `content` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `used_variables` json DEFAULT NULL,
  `description` text COLLATE utf8mb4_unicode_ci,
  `version` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `is_public` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contract_templates_created_by_foreign` (`user_id`),
  KEY `contract_templates_status_index` (`status`),
  KEY `contract_templates_tenant_id_index` (`tenant_id`),
  CONSTRAINT `contract_templates_created_by_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contract_templates`;

CREATE TABLE IF NOT EXISTS `contratadas` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `client_user_id` bigint unsigned DEFAULT NULL,
  `client_type` enum('pj','pf') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pj',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `individual_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cnpj` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cpf` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `birth_date` date DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_secundario` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `alternative_phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `complement` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `district` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `zip_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notes` text COLLATE utf8mb4_unicode_ci,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contratadas_status_index` (`status`),
  KEY `contratadas_contratada_type_index` (`client_type`),
  KEY `contratadas_cnpj_index` (`cnpj`),
  KEY `contratadas_cpf_index` (`cpf`),
  KEY `contratadas_contratada_user_id_foreign` (`client_user_id`),
  KEY `contratadas_user_id_foreign` (`user_id`),
  KEY `contratadas_tenant_id_index` (`tenant_id`),
  CONSTRAINT `contratadas_contratada_user_id_foreign` FOREIGN KEY (`client_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contratadas_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contratadas`;

CREATE TABLE IF NOT EXISTS `contratada_update_tokens` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `contratada_id` bigint unsigned NOT NULL,
  `contract_id` bigint unsigned DEFAULT NULL,
  `token` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL,
  `expires_at` timestamp NOT NULL,
  `used` tinyint(1) NOT NULL DEFAULT '0',
  `used_at` timestamp NULL DEFAULT NULL,
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `contratada_update_tokens_token_unique` (`token`),
  KEY `contratada_update_tokens_token_index` (`token`),
  KEY `contratada_update_tokens_contratada_id_used_index` (`contratada_id`,`used`),
  KEY `contratada_update_tokens_contract_id_index` (`contract_id`),
  CONSTRAINT `contratada_update_tokens_contract_id_foreign` FOREIGN KEY (`contract_id`) REFERENCES `contracts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `contratada_update_tokens_contratada_id_foreign` FOREIGN KEY (`contratada_id`) REFERENCES `contratadas` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contratada_update_tokens`;

CREATE TABLE IF NOT EXISTS `contratantes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `client_user_id` bigint unsigned DEFAULT NULL,
  `client_type` enum('pj','pf') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pj',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `individual_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cnpj` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `cpf` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `birth_date` date DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email_secundario` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `alternative_phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `complement` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `district` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `zip_code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notes` text COLLATE utf8mb4_unicode_ci,
  `status` enum('active','inactive') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `contratantes_user_id_foreign` (`user_id`),
  KEY `contratantes_client_user_id_foreign` (`client_user_id`),
  KEY `contratantes_client_type_index` (`client_type`),
  KEY `contratantes_status_index` (`status`),
  KEY `contratantes_tenant_id_index` (`tenant_id`),
  CONSTRAINT `contratantes_client_user_id_foreign` FOREIGN KEY (`client_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `contratantes_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `contratantes`;

CREATE TABLE IF NOT EXISTS `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `failed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `failed_jobs_uuid_unique` (`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `failed_jobs`;

CREATE TABLE IF NOT EXISTS `jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `queue` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `attempts` tinyint unsigned NOT NULL,
  `reserved_at` int unsigned DEFAULT NULL,
  `available_at` int unsigned NOT NULL,
  `created_at` int unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `jobs_queue_index` (`queue`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `jobs`;

CREATE TABLE IF NOT EXISTS `job_batches` (
  `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `total_jobs` int NOT NULL,
  `pending_jobs` int NOT NULL,
  `failed_jobs` int NOT NULL,
  `failed_job_ids` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `options` mediumtext COLLATE utf8mb4_unicode_ci,
  `cancelled_at` int DEFAULT NULL,
  `created_at` int NOT NULL,
  `finished_at` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `job_batches`;

CREATE TABLE IF NOT EXISTS `lbodev_marketing_campaigns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `channel` enum('email','whatsapp','both') COLLATE utf8mb4_unicode_ci NOT NULL,
  `audience_type` enum('contacts','contratadas','contratantes','all') COLLATE utf8mb4_unicode_ci NOT NULL,
  `filters` json DEFAULT NULL,
  `message_subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `message_body` text COLLATE utf8mb4_unicode_ci,
  `email_header` text COLLATE utf8mb4_unicode_ci,
  `email_footer` text COLLATE utf8mb4_unicode_ci,
  `status` enum('draft','scheduled','processing','completed','failed') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `scheduled_at` timestamp NULL DEFAULT NULL,
  `total_recipients` int NOT NULL DEFAULT '0',
  `sent_count` int NOT NULL DEFAULT '0',
  `failed_count` int NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `lbodev_marketing_campaigns_tenant_id_index` (`tenant_id`),
  KEY `lbodev_marketing_campaigns_status_index` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `lbodev_marketing_campaigns`;

CREATE TABLE IF NOT EXISTS `lbodev_marketing_opt_outs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `phone` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `channel` enum('email','whatsapp','all') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'all',
  `reason` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lbodev_marketing_opt_outs_tenant_id_email_channel_unique` (`tenant_id`,`email`,`channel`),
  KEY `lbodev_marketing_opt_outs_tenant_id_index` (`tenant_id`),
  KEY `lbodev_marketing_opt_outs_email_index` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `lbodev_marketing_opt_outs`;

CREATE TABLE IF NOT EXISTS `lbodev_notification_email_layouts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `header` text COLLATE utf8mb4_unicode_ci,
  `footer` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lbodev_notification_email_layouts_tenant_id_unique` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `lbodev_notification_email_layouts`;

CREATE TABLE IF NOT EXISTS `lbodev_notification_event_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `event_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `send_email` tinyint(1) NOT NULL DEFAULT '1',
  `send_whatsapp` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lbodev_notification_event_settings_tenant_id_event_key_unique` (`tenant_id`,`event_key`),
  KEY `lbodev_notification_event_settings_tenant_id_index` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `lbodev_notification_event_settings`;

CREATE TABLE IF NOT EXISTS `lbodev_notification_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `channel` enum('email','whatsapp') COLLATE utf8mb4_unicode_ci NOT NULL,
  `event_key` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `header` text COLLATE utf8mb4_unicode_ci,
  `body` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `footer` text COLLATE utf8mb4_unicode_ci,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `lbodev_notification_templates_tenant_id_channel_event_key_unique` (`tenant_id`,`channel`,`event_key`),
  KEY `lbodev_notification_templates_tenant_id_index` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `lbodev_notification_templates`;

CREATE TABLE IF NOT EXISTS `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=61 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `migrations`;
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
	(1, '0001_01_01_000000_create_users_table', 1),
	(2, '0001_01_01_000001_create_cache_table', 1),
	(3, '0001_01_01_000002_create_jobs_table', 1),
	(4, '2026_02_04_141250_create_clients_table', 1),
	(5, '2026_02_04_141251_create_contract_templates_table', 1),
	(6, '2026_02_04_141251_create_contracts_table', 1),
	(7, '2026_02_04_141252_create_contract_data_table', 1),
	(8, '2026_02_04_141252_create_contract_status_logs_table', 1),
	(9, '2026_02_04_141253_create_notifications_table', 1),
	(10, '2026_02_04_150000_create_sessions_table', 1),
	(11, '2026_02_04_151000_create_options_table', 2),
	(12, '2026_02_04_183155_create_company_settings_table', 3),
	(13, '2026_02_05_095228_add_client_type_to_clients_table', 4),
	(14, '2026_02_05_112745_update_clients_table_structure', 5),
	(15, '2026_02_05_112808_fix_clients_unique_indexes', 6),
	(16, '2026_02_05_121329_add_username_to_users_table', 7),
	(17, '2026_02_05_121419_add_client_user_id_to_clients_table', 8),
	(18, '2026_02_05_132915_create_password_reset_tokens_table', 9),
	(19, '2026_02_06_113500_add_whatsapp_settings_to_company_settings_table', 10),
	(20, '2026_02_06_000000_create_activity_logs_table', 11),
	(21, '2026_02_06_123956_create_client_update_tokens_table', 12),
	(22, '2026_02_06_120000_create_whatsapp_contacts_table', 13),
	(23, '2026_02_07_120000_add_status_to_whatsapp_contacts_table', 14),
	(24, '2026_02_11_000000_add_origin_to_whatsapp_contacts_table', 15),
	(25, '2026_02_12_000001_rename_created_by_to_user_id_in_contract_templates', 16),
	(27, '2026_02_12_000004_add_user_id_to_company_settings_table', 17),
	(28, '2026_02_12_000000_update_contract_templates_created_by', 18),
	(29, '2026_02_12_000005_remove_unique_constraint_from_company_document', 19),
	(30, '2026_02_12_000010_add_user_id_to_whatsapp_contacts_table', 20),
	(31, '2026_02_12_000011_add_user_id_to_contracts_table', 21),
	(32, '2026_02_12_000013_add_user_id_to_contract_status_logs_table', 22),
	(33, '2026_02_12_000012_add_user_id_to_contract_data_table', 23),
	(34, '2026_02_12_115020_update_contracts_status_enum', 24),
	(35, '2026_02_12_125908_add_contract_id_to_client_update_tokens_table', 25),
	(36, '2026_02_13_070912_update_contracts_status_enum_to_new_flow', 26),
	(37, '2026_02_13_091848_create_contract_approval_tokens_table', 27),
	(38, '2026_02_13_112019_create_system_settings_table', 28),
	(39, '2026_02_16_000000_rename_clients_to_contratadas', 29),
	(40, '2026_02_16_102120_rename_client_id_to_contratada_id_in_contracts_table', 30),
	(41, '2026_02_18_000000_rename_client_tables_to_contratadas', 31),
	(42, '2026_02_18_010000_rename_legacy_indexes_and_constraints', 32),
	(43, '2026_02_18_020000_normalize_client_named_constraints', 33),
	(44, '2026_02_18_030000_remove_leftover_client_constraints', 34),
	(45, '2026_02_21_000000_create_contratantes_table', 35),
	(46, '2026_02_21_010000_add_contratante_id_to_contracts_table', 36),
	(47, '2026_06_02_120000_add_tenant_id_foundation', 37),
	(48, '2026_06_02_121500_add_contract_body_and_template_variable_tracking', 37),
	(49, '2026_06_02_123500_create_notification_and_marketing_tables', 37),
	(50, '2026_06_02_124500_expand_user_roles_for_tenant_rbac', 37),
	(51, '2026_06_02_160000_lbodev_marco5_marketing_compliance', 38),
	(52, '2026_06_05_000001_lbodev_marketing_contacts_opt_out', 39),
	(53, '2026_06_05_120000_lbodev_add_email_template_fields_to_marketing_campaigns', 40),
	(54, '2026_06_06_140000_lbodev_notification_template_redesign', 41),
	(55, '2026_06_06_120000_add_phase_events_to_contracts_table', 42),
	(56, '2026_06_06_140000_create_notas_fiscais_table', 43),
	(57, '2026_06_06_150000_add_amount_to_contracts_table', 44),
	(58, '2026_06_07_180000_backfill_paid_at_on_notas_fiscais', 45),
	(59, '2026_06_07_190000_backfill_signed_at_on_contracts', 46),
	(60, '2026_06_07_000000_simplify_user_roles_single_install', 47);

CREATE TABLE IF NOT EXISTS `notas_fiscais` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `contract_id` bigint unsigned NOT NULL,
  `contratante_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `number` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
  `series` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '1',
  `type` enum('nfe','nfse','nfce','recibo','outro') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'nfse',
  `status` enum('draft','issued','sent','paid','cancelled') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `issue_date` date NOT NULL,
  `due_date` date DEFAULT NULL,
  `amount` decimal(12,2) NOT NULL,
  `tax_amount` decimal(12,2) DEFAULT NULL,
  `access_key` varchar(44) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_unicode_ci,
  `notes` text COLLATE utf8mb4_unicode_ci,
  `cancellation_reason` text COLLATE utf8mb4_unicode_ci,
  `file_path` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_original_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_mime` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_size` bigint unsigned DEFAULT NULL,
  `sent_at` timestamp NULL DEFAULT NULL,
  `sent_to_email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sent_by_user_id` bigint unsigned DEFAULT NULL,
  `paid_at` timestamp NULL DEFAULT NULL,
  `cancelled_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_notas_fiscais_tenant_numero_serie` (`tenant_id`,`number`,`series`),
  KEY `notas_fiscais_contratante_id_foreign` (`contratante_id`),
  KEY `notas_fiscais_user_id_foreign` (`user_id`),
  KEY `notas_fiscais_sent_by_user_id_foreign` (`sent_by_user_id`),
  KEY `notas_fiscais_issue_date_index` (`issue_date`),
  KEY `notas_fiscais_contract_id_index` (`contract_id`),
  KEY `notas_fiscais_tenant_id_index` (`tenant_id`),
  KEY `notas_fiscais_status_index` (`status`),
  CONSTRAINT `notas_fiscais_contract_id_foreign` FOREIGN KEY (`contract_id`) REFERENCES `contracts` (`id`) ON DELETE CASCADE,
  CONSTRAINT `notas_fiscais_contratante_id_foreign` FOREIGN KEY (`contratante_id`) REFERENCES `contratantes` (`id`) ON DELETE SET NULL,
  CONSTRAINT `notas_fiscais_sent_by_user_id_foreign` FOREIGN KEY (`sent_by_user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `notas_fiscais_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `notas_fiscais`;

CREATE TABLE IF NOT EXISTS `notifications` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `channel` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'mail',
  `subject` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `message` text COLLATE utf8mb4_unicode_ci,
  `data` json DEFAULT NULL,
  `status` enum('pending','sent','failed') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `sent_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `notifications_user_id_foreign` (`user_id`),
  CONSTRAINT `notifications_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `notifications`;

CREATE TABLE IF NOT EXISTS `options` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` text COLLATE utf8mb4_unicode_ci,
  `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `options_key_unique` (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `options`;

CREATE TABLE IF NOT EXISTS `password_reset_tokens` (
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `password_reset_tokens`;

CREATE TABLE IF NOT EXISTS `sessions` (
  `id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `user_agent` text COLLATE utf8mb4_unicode_ci,
  `payload` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
  `last_activity` int NOT NULL,
  PRIMARY KEY (`id`),
  KEY `sessions_user_id_index` (`user_id`),
  KEY `sessions_last_activity_index` (`last_activity`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `sessions`;

CREATE TABLE IF NOT EXISTS `system_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` text COLLATE utf8mb4_unicode_ci,
  `type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'string',
  `group` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'general',
  `description` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `system_settings_key_unique` (`key`),
  KEY `system_settings_key_group_index` (`key`,`group`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `system_settings`;
INSERT INTO `system_settings` (`id`, `key`, `value`, `type`, `group`, `description`, `created_at`, `updated_at`) VALUES
	(1, 'use_queues_for_notifications', '1', 'string', 'general', NULL, '2026-02-13 14:23:23', '2026-06-05 19:15:54'),
	(2, 'queue_connection', 'database', 'string', 'general', NULL, '2026-02-13 14:23:23', '2026-06-05 19:15:55'),
	(3, 'max_queue_attempts', '3', 'integer', 'queues', 'Maximum attempts for failed jobs', '2026-02-13 14:23:23', '2026-02-13 14:23:23'),
	(4, 'max_job_attempts', '3', 'string', 'general', NULL, '2026-02-13 15:09:29', '2026-02-13 15:09:29'),
	(5, 'queue_worker_enabled', '', 'boolean', 'general', NULL, '2026-02-13 15:30:37', '2026-02-14 10:53:06');

CREATE TABLE IF NOT EXISTS `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `role` enum('admin','contratante','contratada') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'admin',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_email_unique` (`email`),
  UNIQUE KEY `users_username_unique` (`username`),
  KEY `users_role_index` (`role`),
  KEY `users_tenant_id_index` (`tenant_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `users`;
INSERT INTO `users` (`id`, `tenant_id`, `name`, `username`, `email`, `email_verified_at`, `password`, `phone`, `remember_token`, `role`, `is_active`, `created_at`, `updated_at`, `deleted_at`) VALUES
	(1, 1, 'LBO Dev Full Stack', NULL, 'livio.bruno.oliveira@gmail.com', '2026-02-04 17:33:36', '$2y$12$XcF6Bn9EeQmTp5JPcWtwSOaLmLUl.zjJV3mtFuBL2EheHowXPFXLS', NULL, 'TGTmWsZN0NT3fZp9dMNznL7UE3EH0u2ldeu4mhpuUIPKdmGdxuMB9fOh1Ybh', 'admin', 1, '2026-02-04 17:33:36', '2026-02-04 17:33:36', NULL);

CREATE TABLE IF NOT EXISTS `whatsapp_contacts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `user_id` bigint unsigned NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `city` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `status` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `marketing_opt_out_at` timestamp NULL DEFAULT NULL,
  `origin` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT 'manual',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `whatsapp_contacts_status_index` (`status`),
  KEY `whatsapp_contacts_user_id_foreign` (`user_id`),
  KEY `whatsapp_contacts_tenant_id_index` (`tenant_id`),
  CONSTRAINT `whatsapp_contacts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DELETE FROM `whatsapp_contacts`;

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
