/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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 */;
DROP TABLE IF EXISTS `addresses`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `addresses` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `address_line1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address_line2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `zip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `latitude` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `longitude` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_primary` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `addresses_user_id_foreign` (`user_id`),
  CONSTRAINT `addresses_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `agencies`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agencies` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `name` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `company_name` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `website` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `office_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `secondary_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `office_phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `mobile_phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fax` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `zip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `latitude` decimal(10,8) DEFAULT NULL,
  `longitude` decimal(11,8) DEFAULT NULL,
  `notes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_agencies_tenant_code` (`tenant_id`,`code`),
  UNIQUE KEY `uk_agencies_tenant_name` (`tenant_id`,`name`),
  KEY `idx_agencies_tenant_active` (`tenant_id`,`is_active`),
  KEY `idx_agencies_office_email` (`office_email`),
  CONSTRAINT `agencies_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `agency_memberships`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agency_memberships` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `agency_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `user_type_id` bigint unsigned NOT NULL,
  `role_id` bigint unsigned NOT NULL,
  `status` enum('active','invited','suspended') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'active',
  `is_primary` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_am_agency_user_type` (`agency_id`,`user_id`,`user_type_id`),
  KEY `agency_memberships_user_type_id_foreign` (`user_type_id`),
  KEY `idx_am_user` (`user_id`),
  KEY `idx_am_agency` (`agency_id`),
  KEY `idx_am_role` (`role_id`),
  CONSTRAINT `agency_memberships_agency_id_foreign` FOREIGN KEY (`agency_id`) REFERENCES `agencies` (`id`) ON DELETE CASCADE,
  CONSTRAINT `agency_memberships_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `agency_memberships_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `agency_memberships_user_type_id_foreign` FOREIGN KEY (`user_type_id`) REFERENCES `user_types` (`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `agent_sponsors`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agent_sponsors` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `agent_id` bigint unsigned NOT NULL,
  `inspector_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `agent_sponsors_agent_id_index` (`agent_id`),
  KEY `agent_sponsors_inspector_id_index` (`inspector_id`),
  CONSTRAINT `agent_sponsors_agent_id_foreign` FOREIGN KEY (`agent_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `agent_sponsors_inspector_id_foreign` FOREIGN KEY (`inspector_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `agreement_versions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agreement_versions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `agreement_id` bigint unsigned NOT NULL,
  `version_no` int unsigned NOT NULL,
  `description_html` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `edited_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agreement_version` (`agreement_id`,`version_no`),
  KEY `fk_agreement_versions_edited_by` (`edited_by`),
  CONSTRAINT `fk_agreement_versions_agreement` FOREIGN KEY (`agreement_id`) REFERENCES `agreements` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_agreement_versions_edited_by` FOREIGN KEY (`edited_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `agreements`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `agreements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `master_language_id` bigint unsigned DEFAULT NULL,
  `state` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description_html` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `inspector_sign_required` tinyint(1) NOT NULL DEFAULT '0',
  `is_change_order` tinyint(1) NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_agreements_tenant_name` (`tenant_id`,`name`),
  KEY `fk_agreements_service` (`service_id`),
  KEY `fk_agreements_created_by` (`created_by`),
  KEY `fk_agreements_updated_by` (`updated_by`),
  KEY `agreements_master_language_id_index` (`master_language_id`),
  CONSTRAINT `agreements_master_language_id_foreign` FOREIGN KEY (`master_language_id`) REFERENCES `master_languages` (`id`) ON DELETE SET NULL,
  CONSTRAINT `agreements_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `fk_agreements_created_by` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `fk_agreements_service` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`),
  CONSTRAINT `fk_agreements_updated_by` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `association_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `association_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL DEFAULT '0',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `association_types_tenant_id_index` (`tenant_id`),
  CONSTRAINT `association_types_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `attachment_folders`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `attachment_folders` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `parent_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `is_visible` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_af_tenant_parent_name` (`tenant_id`,`parent_id`,`name`),
  KEY `idx_af_parent` (`parent_id`),
  CONSTRAINT `attachment_folders_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `attachment_folders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `attachment_folders_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `attachments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `attachments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `folder_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `uploaded_by` bigint unsigned DEFAULT NULL,
  `is_visible` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `meta` json NOT NULL DEFAULT (json_object()),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_att_tenant_folder_name` (`tenant_id`,`folder_id`,`name`),
  KEY `attachments_folder_id_foreign` (`folder_id`),
  KEY `attachments_uploaded_by_foreign` (`uploaded_by`),
  KEY `idx_att_tenant_folder` (`tenant_id`,`folder_id`),
  KEY `attachments_template_id_index` (`template_id`),
  CONSTRAINT `attachments_folder_id_foreign` FOREIGN KEY (`folder_id`) REFERENCES `attachment_folders` (`id`) ON DELETE SET NULL,
  CONSTRAINT `attachments_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `attachments_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `attachments_uploaded_by_foreign` FOREIGN KEY (`uploaded_by`) REFERENCES `users` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `cdns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `cdns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `status` tinyint unsigned NOT NULL DEFAULT '1',
  `cdn_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `cdn_root` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `location_type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'public' COMMENT 'public or s3',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `client_discounts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `client_discounts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `discount_type` enum('Percentage','Fixed') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `amount` decimal(10,2) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_client_discounts_title` (`tenant_id`,`title`),
  CONSTRAINT `client_discounts_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `comment_bookmarks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `comment_bookmarks` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `comment_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `comment_diy`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `comment_diy` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `category_id` bigint unsigned NOT NULL,
  `comment_id` bigint unsigned NOT NULL,
  `type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `link` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint NOT NULL DEFAULT '1' COMMENT '0: Inactive, 1: Active',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `comment_diy_category_id_foreign` (`category_id`),
  KEY `comment_diy_comment_id_foreign` (`comment_id`),
  CONSTRAINT `comment_diy_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `section_item_categories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `comment_diy_comment_id_foreign` FOREIGN KEY (`comment_id`) REFERENCES `section_comments` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `comment_favourites`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `comment_favourites` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `comment_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `customer_agent_mappings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `customer_agent_mappings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `customer_id` bigint unsigned NOT NULL,
  `agent_id` bigint unsigned NOT NULL,
  `created_by` bigint unsigned 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 `uq_customer_agent_per_tenant` (`tenant_id`,`customer_id`,`agent_id`),
  KEY `idx_customer_lookup` (`tenant_id`,`customer_id`),
  KEY `idx_agent_lookup` (`tenant_id`,`agent_id`),
  KEY `customer_agent_mappings_customer_id_foreign` (`customer_id`),
  KEY `customer_agent_mappings_agent_id_foreign` (`agent_id`),
  KEY `customer_agent_mappings_created_by_foreign` (`created_by`),
  CONSTRAINT `customer_agent_mappings_agent_id_foreign` FOREIGN KEY (`agent_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `customer_agent_mappings_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `customer_agent_mappings_customer_id_foreign` FOREIGN KEY (`customer_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `customer_agent_mappings_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `customer_agent_type_options`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `customer_agent_type_options` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `option` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `customer_agent_type_options_tenant_id_foreign` (`tenant_id`),
  CONSTRAINT `customer_agent_type_options_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `customer_agent_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `customer_agent_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_type_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `settings` json DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_tenant_ut_title` (`tenant_id`,`user_type_id`,`title`),
  KEY `customer_agent_types_user_type_id_foreign` (`user_type_id`),
  CONSTRAINT `customer_agent_types_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `customer_agent_types_user_type_id_foreign` FOREIGN KEY (`user_type_id`) REFERENCES `user_types` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `defect_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `defect_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `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 `uq_defect_tenant_name` (`tenant_id`,`name`),
  CONSTRAINT `defect_types_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `discount_coupon_service_rules`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `discount_coupon_service_rules` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `coupon_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned DEFAULT NULL,
  `discount_type` enum('Percentage','Fixed') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Percentage',
  `discount_value` decimal(10,4) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `service_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`service_id`,0)) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dcsr` (`coupon_id`,`service_key`),
  CONSTRAINT `fk_dcsr_coupon` FOREIGN KEY (`coupon_id`) REFERENCES `discount_coupons` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `discount_coupons`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `discount_coupons` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `audience` enum('All','Customer','Agent','Customer_Agent') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'All',
  `max_uses_per_user` int unsigned NOT NULL DEFAULT '0',
  `max_unique_users` int unsigned DEFAULT NULL,
  `change_service_price` tinyint(1) NOT NULL DEFAULT '0',
  `starts_at` timestamp NULL DEFAULT NULL,
  `expires_at` timestamp NULL DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_dc_code` (`tenant_id`,`code`),
  CONSTRAINT `discount_coupons_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `employee_time_offs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `employee_time_offs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `start_time` time DEFAULT NULL,
  `end_time` time DEFAULT NULL,
  `full_day` tinyint(1) NOT NULL DEFAULT '1',
  `status` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending',
  `reason` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `approved_by` bigint unsigned DEFAULT NULL,
  `approved_at` timestamp NULL DEFAULT NULL,
  `denied_by` bigint unsigned DEFAULT NULL,
  `denied_at` timestamp NULL DEFAULT NULL,
  `admin_note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `employee_time_offs_user_id_foreign` (`user_id`),
  KEY `employee_time_offs_approved_by_foreign` (`approved_by`),
  KEY `employee_time_offs_denied_by_foreign` (`denied_by`),
  KEY `employee_time_offs_tenant_id_user_id_index` (`tenant_id`,`user_id`),
  KEY `employee_time_offs_tenant_id_start_date_index` (`tenant_id`,`start_date`),
  KEY `employee_time_offs_tenant_id_status_index` (`tenant_id`,`status`),
  CONSTRAINT `employee_time_offs_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `employee_time_offs_denied_by_foreign` FOREIGN KEY (`denied_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `employee_time_offs_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `employee_time_offs_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `error_logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `error_logs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned DEFAULT '0',
  `line_number` smallint unsigned DEFAULT '0',
  `class_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `method_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `error_message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `request_params` json DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `failed_jobs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `failed_jobs` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `connection` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `queue` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `payload` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `exception` longtext CHARACTER SET utf8mb4 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;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `files`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `files` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `entity_id` bigint unsigned NOT NULL DEFAULT '0',
  `entity_type` tinyint unsigned NOT NULL DEFAULT '0',
  `cdn_id` bigint unsigned NOT NULL DEFAULT '0',
  `file_name` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `file_name_original` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `file_ext` varchar(6) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `file_mime` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `location` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'file uri/location on server or s3',
  `file_size` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `files_entity_id_index` (`entity_id`),
  KEY `files_cdn_id_foreign` (`cdn_id`),
  CONSTRAINT `files_cdn_id_foreign` FOREIGN KEY (`cdn_id`) REFERENCES `cdns` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `foundation_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `foundation_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_foundation_types_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_attachments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_attachments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'Associated inspection (no FK if inspections table absent)',
  `master_attachment_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master attachment if applicable',
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `inspection_template_id` bigint unsigned DEFAULT NULL COMMENT 'References inspection_templates.id (no FK enforced)',
  `folder_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `uploaded_by` bigint unsigned DEFAULT NULL,
  `is_visible` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `meta` json DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspection_attachments_tenant_id_template_id_index` (`tenant_id`,`template_id`),
  KEY `inspection_attachments_tenant_id_is_active_index` (`tenant_id`,`is_active`),
  KEY `inspection_attachments_tenant_id_is_visible_index` (`tenant_id`,`is_visible`),
  KEY `inspection_attachments_inspection_id_index` (`inspection_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_comment_diy`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_comment_diy` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'Associated inspection',
  `category_id` bigint unsigned NOT NULL COMMENT 'Inspection category id (inspection_section_item_categories)',
  `comment_id` bigint unsigned NOT NULL COMMENT 'Inspection comment id (inspection_section_comments)',
  `type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Copied from master comment_diy if applicable',
  `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `link` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint NOT NULL DEFAULT '1' COMMENT '0: Inactive, 1: Active',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `inspection_comment_diy_category_id_foreign` (`category_id`),
  KEY `inspection_comment_diy_comment_id_foreign` (`comment_id`),
  KEY `inspection_comment_diy_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_comment_diy_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `inspection_section_item_categories` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspection_comment_diy_comment_id_foreign` FOREIGN KEY (`comment_id`) REFERENCES `inspection_section_comments` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_item_bookmarks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_item_bookmarks` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `item_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `inspection_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `inspection_item_bookmarks_item_id_user_id_inspection_id_unique` (`item_id`,`user_id`,`inspection_id`),
  KEY `inspection_item_bookmarks_item_id_user_id_inspection_id_index` (`item_id`,`user_id`,`inspection_id`),
  KEY `inspection_item_bookmarks_user_id_index` (`user_id`),
  KEY `inspection_item_bookmarks_inspection_id_index` (`inspection_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_item_files`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_item_files` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `inspection_id` bigint unsigned NOT NULL,
  `inspection_item_id` bigint unsigned NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_size` bigint unsigned NOT NULL,
  `mime_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspection_item_files_tenant_id_inspection_id_index` (`tenant_id`,`inspection_id`),
  KEY `inspection_item_files_inspection_item_id_index` (`inspection_item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_material_answers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_material_answers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `material_id` bigint unsigned NOT NULL,
  `answer` text COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_material_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_material_categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `inspection_template_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `control_type` enum('text','textarea','number','select','multiselect','checkbox','radio','date','time','datetime','file') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `control_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `control_options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add_to_reports` tinyint NOT NULL DEFAULT '0',
  `display_in_editor` tinyint NOT NULL DEFAULT '0',
  `is_primary_group` tinyint NOT NULL DEFAULT '0',
  `description` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `master_material_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master material if applicable',
  `tenant_id` bigint unsigned NOT NULL,
  `item_id` bigint unsigned NOT NULL,
  `group_category_id` bigint unsigned DEFAULT NULL COMMENT 'Optional grouping',
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_duplicate` tinyint NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_insp_material_category_per_item_title_with_deleted` (`tenant_id`,`item_id`,`title`,`inspection_id`,`deleted_at`),
  KEY `inspection_material_categories_item_id_foreign` (`item_id`),
  KEY `inspection_material_categories_tenant_id_group_category_id_index` (`tenant_id`,`group_category_id`),
  KEY `inspection_material_categories_tenant_id_is_active_index` (`tenant_id`,`is_active`),
  KEY `inspection_material_categories_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_material_categories_item_id_foreign` FOREIGN KEY (`item_id`) REFERENCES `inspection_section_items` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspection_material_categories_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_report_comments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_report_comments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'Links to inspection (no FK if inspections table absent)',
  `master_comment_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master comment if applicable',
  `type` enum('introduction','cover_letter','closing_statement') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'introduction',
  `tenant_id` bigint unsigned NOT NULL COMMENT 'Tenant scope',
  `inspection_template_id` bigint unsigned DEFAULT NULL COMMENT 'References inspection_templates.id (no FK enforced)',
  `auto_include_in_report` tinyint NOT NULL DEFAULT '0' COMMENT '1 = auto include this comment in generated report',
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint NOT NULL DEFAULT '1' COMMENT '0: Inactive, 1: Active',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspection_report_comments_tenant_id_category_id_index` (`tenant_id`),
  KEY `inspection_report_comments_tenant_id_section_id_index` (`tenant_id`),
  KEY `inspection_report_comments_tenant_id_section_item_id_index` (`tenant_id`),
  KEY `inspection_report_comments_tenant_id_priority_id_index` (`tenant_id`),
  KEY `inspection_report_comments_tenant_id_master_language_id_index` (`tenant_id`),
  KEY `inspection_report_comments_tenant_id_is_active_index` (`tenant_id`,`is_active`),
  KEY `inspection_report_comments_inspection_id_index` (`inspection_id`),
  KEY `inspection_report_comments_tenant_id_type_index` (`tenant_id`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_report_question_options`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_report_question_options` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `inspection_template_id` bigint unsigned NOT NULL,
  `question_id` bigint unsigned NOT NULL,
  `option_id` bigint unsigned NOT NULL DEFAULT '0',
  `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_report_questions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_report_questions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'Associated inspection (no FK if inspections table absent)',
  `master_question_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master question if applicable',
  `tenant_id` bigint unsigned NOT NULL,
  `question` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `type` enum('text','textarea','number','radio','checkbox','select','date','time','datetime') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'text',
  `show_separately` tinyint(1) NOT NULL DEFAULT '0',
  `is_required` tinyint(1) NOT NULL DEFAULT '0',
  `settings` json NOT NULL DEFAULT (json_object()),
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_irq_tenant` (`tenant_id`),
  KEY `inspection_report_questions_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_report_questions_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_report_sections`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_report_sections` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'Associated inspection (no FK if inspections table absent)',
  `master_section_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master section if applicable',
  `tenant_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `color_code` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `include_by_default` tinyint(1) NOT NULL DEFAULT '0',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `inspection_template_id` bigint unsigned DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_insp_section_tenant_title_inspection` (`tenant_id`,`title`,`inspection_id`),
  KEY `inspection_report_sections_inspection_id_index` (`inspection_id`),
  KEY `inspection_report_sections_template_id_foreign` (`inspection_template_id`),
  CONSTRAINT `inspection_report_sections_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_section_comments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_section_comments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `master_comment_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to master comment if applicable',
  `tenant_id` bigint unsigned NOT NULL,
  `section_id` bigint unsigned DEFAULT NULL,
  `section_item_id` bigint unsigned DEFAULT NULL,
  `category_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `priority_id` bigint unsigned DEFAULT NULL,
  `master_language_id` bigint unsigned DEFAULT NULL,
  `summary_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `display_in_editor` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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`),
  KEY `inspection_section_comments_section_id_foreign` (`section_id`),
  KEY `inspection_section_comments_section_item_id_foreign` (`section_item_id`),
  KEY `inspection_section_comments_category_id_foreign` (`category_id`),
  KEY `inspection_section_comments_tenant_id_category_id_index` (`tenant_id`,`category_id`),
  KEY `inspection_section_comments_tenant_id_section_id_index` (`tenant_id`,`section_id`),
  KEY `inspection_section_comments_tenant_id_section_item_id_index` (`tenant_id`,`section_item_id`),
  KEY `inspection_section_comments_tenant_id_priority_id_index` (`tenant_id`,`priority_id`),
  KEY `inspection_section_comments_tenant_id_is_active_index` (`tenant_id`,`is_active`),
  KEY `inspection_section_comments_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_section_comments_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `inspection_section_item_categories` (`id`) ON DELETE SET NULL,
  CONSTRAINT `inspection_section_comments_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `inspection_report_sections` (`id`) ON DELETE SET NULL,
  CONSTRAINT `inspection_section_comments_section_item_id_foreign` FOREIGN KEY (`section_item_id`) REFERENCES `inspection_section_items` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_section_files`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_section_files` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `section_id` bigint unsigned NOT NULL,
  `inspection_id` bigint unsigned NOT NULL,
  `filename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `original_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_size` bigint unsigned NOT NULL,
  `uploaded_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspection_section_files_section_id_index` (`section_id`),
  KEY `inspection_section_files_inspection_id_index` (`inspection_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_section_item_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_section_item_categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `section_id` bigint unsigned NOT NULL,
  `item_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `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,
  `master_category_id` bigint NOT NULL DEFAULT '0' COMMENT 'Reference to master category; 0 = none',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_insp_item_category_per_item_title_with_deleted` (`tenant_id`,`section_id`,`item_id`,`title`,`inspection_id`,`deleted_at`),
  KEY `inspection_section_item_categories_section_id_foreign` (`section_id`),
  KEY `inspection_section_item_categories_item_id_foreign` (`item_id`),
  KEY `inspection_section_item_categories_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_section_item_categories_item_id_foreign` FOREIGN KEY (`item_id`) REFERENCES `inspection_section_items` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspection_section_item_categories_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `inspection_report_sections` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspection_section_item_categories_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_section_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_section_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL,
  `master_item_id` bigint unsigned DEFAULT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `section_id` bigint unsigned NOT NULL,
  `item_type_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `default_section_column_id` bigint unsigned DEFAULT NULL,
  `defect_type_id` bigint unsigned DEFAULT NULL,
  `is_required` tinyint(1) NOT NULL DEFAULT '0',
  `display_in_editor` tinyint(1) NOT NULL DEFAULT '0',
  `settings` json NOT NULL DEFAULT (json_object()),
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `item_status` tinyint NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_insp_item_per_section_title_with_deleted` (`tenant_id`,`section_id`,`title`,`inspection_id`,`deleted_at`),
  KEY `inspection_section_items_default_section_column_id_foreign` (`default_section_column_id`),
  KEY `inspection_section_items_defect_type_id_foreign` (`defect_type_id`),
  KEY `idx_insp_section_items_section` (`section_id`),
  KEY `inspection_section_items_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_section_items_default_section_column_id_foreign` FOREIGN KEY (`default_section_column_id`) REFERENCES `section_columns` (`id`) ON DELETE SET NULL,
  CONSTRAINT `inspection_section_items_defect_type_id_foreign` FOREIGN KEY (`defect_type_id`) REFERENCES `defect_types` (`id`) ON DELETE SET NULL,
  CONSTRAINT `inspection_section_items_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `inspection_report_sections` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspection_section_items_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `inspection_id` bigint unsigned DEFAULT NULL COMMENT 'Optional link to an inspection entity (no FK yet)',
  `master_template_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to original template (templates.id)',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `file_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `type` enum('pdf','docx','html') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pdf',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_default` tinyint(1) NOT NULL DEFAULT '0',
  `sort_order` int NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `inspection_templates_slug_unique` (`slug`),
  KEY `inspection_templates_tenant_id_is_active_index` (`tenant_id`,`is_active`),
  KEY `inspection_templates_inspection_id_index` (`inspection_id`),
  KEY `inspection_templates_master_template_id_index` (`master_template_id`),
  CONSTRAINT `inspection_templates_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_inspection_types_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspection_users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspection_users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_id` bigint unsigned NOT NULL COMMENT 'References inspection entity (no FK if table not present)',
  `template_id` bigint unsigned DEFAULT NULL COMMENT 'Reference to inspection template if applicable',
  `user_id` bigint unsigned NOT NULL,
  `is_favourite` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `inspection_users_inspection_id_user_id_unique` (`inspection_id`,`user_id`),
  KEY `inspection_users_user_id_foreign` (`user_id`),
  KEY `inspection_users_inspection_id_index` (`inspection_id`),
  CONSTRAINT `inspection_users_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspector_associations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspector_associations` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `association_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `association_name` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `association_license_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort_order` int NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `display_in_profile` tinyint NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspector_associations_user_id_foreign` (`user_id`),
  CONSTRAINT `inspector_associations_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspector_profiles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspector_profiles` (
  `user_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `license_number` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sponsor_user_id` bigint unsigned DEFAULT NULL,
  `is_subcontractor` tinyint(1) NOT NULL DEFAULT '0',
  `calendar_color` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `event_color` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `timeoff_color` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `online_resume_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `office_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`user_id`),
  KEY `fk_inspector_sponsor` (`sponsor_user_id`),
  CONSTRAINT `fk_inspector_sponsor` FOREIGN KEY (`sponsor_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_inspector_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspector_time_off`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspector_time_off` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL COMMENT 'Tenant ID for multi-tenant isolation',
  `inspector_user_id` bigint unsigned NOT NULL COMMENT 'Inspector/Employee user ID',
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Time off title/reason',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'Detailed description of time off',
  `start_date` date NOT NULL COMMENT 'Time off start date',
  `end_date` date NOT NULL COMMENT 'Time off end date',
  `start_time` time DEFAULT NULL,
  `end_time` time DEFAULT NULL,
  `time_off_first` time DEFAULT NULL,
  `time_off_second` time DEFAULT NULL,
  `status` enum('pending','approved','rejected','cancelled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'pending' COMMENT 'Time off request status',
  `approved_by` bigint unsigned DEFAULT NULL COMMENT 'User ID who approved/rejected this request',
  `approved_at` timestamp NULL DEFAULT NULL COMMENT 'When the request was approved/rejected',
  `approval_notes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'Notes from approver',
  `created_by` bigint unsigned NOT NULL COMMENT 'User who created this time off request',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `inspector_time_off_inspector_user_id_foreign` (`inspector_user_id`),
  KEY `inspector_time_off_approved_by_foreign` (`approved_by`),
  KEY `inspector_time_off_created_by_foreign` (`created_by`),
  KEY `inspector_time_off_tenant_id_inspector_user_id_index` (`tenant_id`,`inspector_user_id`),
  KEY `inspector_time_off_start_date_end_date_index` (`start_date`,`end_date`),
  KEY `inspector_time_off_status_index` (`status`),
  CONSTRAINT `inspector_time_off_approved_by_foreign` FOREIGN KEY (`approved_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `inspector_time_off_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspector_time_off_inspector_user_id_foreign` FOREIGN KEY (`inspector_user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspector_time_off_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `inspector_time_off_schedules`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `inspector_time_off_schedules` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspector_time_off_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_timeoff_schedule` (`inspector_time_off_id`,`schedule_id`),
  KEY `idx_timeoff_tenant` (`inspector_time_off_id`,`tenant_id`),
  KEY `idx_schedule_tenant` (`schedule_id`,`tenant_id`),
  KEY `idx_tenant` (`tenant_id`),
  CONSTRAINT `inspector_time_off_schedules_inspector_time_off_id_foreign` FOREIGN KEY (`inspector_time_off_id`) REFERENCES `inspector_time_off` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspector_time_off_schedules_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `inspector_time_off_schedules_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `invoice_contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `invoice_contacts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `contact_type` enum('customer','agent','inspector') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_primary` tinyint(1) NOT NULL DEFAULT '0',
  `display_order` int NOT NULL DEFAULT '0',
  `full_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `schedule_metadata` json DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `invoice_contact_unique` (`invoice_id`,`user_id`,`contact_type`),
  KEY `invoice_contacts_user_id_foreign` (`user_id`),
  KEY `invoice_contacts_invoice_id_contact_type_index` (`invoice_id`,`contact_type`),
  KEY `invoice_contacts_invoice_id_is_primary_index` (`invoice_id`,`is_primary`),
  CONSTRAINT `invoice_contacts_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE,
  CONSTRAINT `invoice_contacts_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `invoice_notes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `invoice_notes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `language_id` bigint unsigned NOT NULL,
  `invoice_note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `invoice_notes_tenant_id_index` (`tenant_id`),
  KEY `invoice_notes_language_id_index` (`language_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `invoice_payments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `invoice_payments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `payment_date` date NOT NULL,
  `payment_method` enum('cash','check','credit_card','debit_card','bank_transfer','paypal','stripe','square','venmo','zelle','other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'cash',
  `reference_number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `gateway` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `gateway_response` json DEFAULT NULL,
  `status` enum('pending','completed','failed','refunded') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'completed',
  `notes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `recorded_by` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `invoice_payments_recorded_by_foreign` (`recorded_by`),
  KEY `invoice_payments_invoice_id_status_index` (`invoice_id`,`status`),
  KEY `invoice_payments_tenant_id_payment_date_index` (`tenant_id`,`payment_date`),
  KEY `invoice_payments_payment_method_index` (`payment_method`),
  CONSTRAINT `invoice_payments_invoice_id_foreign` FOREIGN KEY (`invoice_id`) REFERENCES `invoices` (`id`) ON DELETE CASCADE,
  CONSTRAINT `invoice_payments_recorded_by_foreign` FOREIGN KEY (`recorded_by`) REFERENCES `users` (`id`),
  CONSTRAINT `invoice_payments_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `invoices`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `invoices` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `invoice_number` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `invoice_date` date NOT NULL,
  `invoice_note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `property_address` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `property_city` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `property_state` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `property_postal_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `primary_client_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `primary_client_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `primary_client_phone` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `base_amount` decimal(10,2) DEFAULT NULL,
  `discount_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `additional_fee_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `subtotal_amount` decimal(10,2) DEFAULT NULL,
  `tax_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `total_amount` decimal(10,2) DEFAULT NULL,
  `coupon_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `coupon_discount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `status` enum('draft','sent','viewed','paid','cancelled','refunded') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'draft',
  `payment_status` enum('unpaid','partial','paid','overdue','refunded') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unpaid',
  `paid_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `due_date` date DEFAULT NULL,
  `sent_at` timestamp NULL DEFAULT NULL,
  `viewed_at` timestamp NULL DEFAULT NULL,
  `paid_at` timestamp NULL DEFAULT NULL,
  `created_by` bigint unsigned DEFAULT NULL,
  `updated_by` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `invoices_invoice_number_unique` (`invoice_number`),
  KEY `invoices_created_by_foreign` (`created_by`),
  KEY `invoices_updated_by_foreign` (`updated_by`),
  KEY `invoices_tenant_id_status_index` (`tenant_id`,`status`),
  KEY `invoices_schedule_id_index` (`schedule_id`),
  KEY `invoices_invoice_date_index` (`invoice_date`),
  KEY `invoices_payment_status_index` (`payment_status`),
  CONSTRAINT `invoices_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
  CONSTRAINT `invoices_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `invoices_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`),
  CONSTRAINT `invoices_updated_by_foreign` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `item_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `item_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int NOT NULL DEFAULT '0' COMMENT 'Display order for item types',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `item_types_tenant_id_foreign` (`tenant_id`),
  CONSTRAINT `item_types_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `master_languages`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `master_languages` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Language name (e.g., English, Spanish, French)',
  `code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Language code (e.g., en, es, fr)',
  `native_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Language name in its native script',
  `iso_639_1` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'ISO 639-1 two-letter code',
  `iso_639_2` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'ISO 639-2 three-letter code',
  `iso_639_3` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'ISO 639-3 three-letter code',
  `region` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Primary region where language is spoken',
  `script` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Writing system used (e.g., Latin, Cyrillic, Arabic)',
  `direction` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ltr' COMMENT 'Text direction: ltr (left-to-right) or rtl (right-to-left)',
  `date_format` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Default date format for the language',
  `time_format` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Default time format for the language',
  `number_format` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Number formatting rules',
  `currency_code` varchar(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Default currency code',
  `is_active` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Whether the language is active and available',
  `is_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether this is the default language',
  `sort_order` int NOT NULL DEFAULT '0' COMMENT 'Display order for language selection',
  `priority` int NOT NULL DEFAULT '0' COMMENT 'Priority for language selection (higher = more important)',
  `metadata` json DEFAULT NULL COMMENT 'Additional language-specific metadata',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'Description of the language',
  `flag_icon` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Flag icon class or image path',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `master_languages_code_unique` (`code`),
  KEY `master_languages_is_active_sort_order_index` (`is_active`,`sort_order`),
  KEY `master_languages_code_is_active_index` (`code`,`is_active`),
  KEY `master_languages_is_default_index` (`is_default`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `master_menus`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `master_menus` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` bigint unsigned DEFAULT '0' COMMENT 'Parent row id',
  `display_order` smallint unsigned DEFAULT '0',
  `status` tinyint unsigned DEFAULT '1',
  `class` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Controller class name',
  `method` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Controller method name',
  `menu` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `icon` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `query_params` json DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `material_bookmarks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `material_bookmarks` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `material_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `material_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `material_categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `item_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `control_type` enum('text','textarea','number','select','multiselect','checkbox','radio','date','time','datetime','file') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'text',
  `control_label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `control_options` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `group_category_id` bigint unsigned DEFAULT NULL,
  `auto_add_to_reports` tinyint(1) NOT NULL DEFAULT '0',
  `display_in_reports` tinyint(1) NOT NULL DEFAULT '0',
  `is_primary_group` tinyint(1) NOT NULL DEFAULT '0',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_matcat_tenant_item_name_with_deleted_at` (`tenant_id`,`item_id`,`name`,`deleted_at`),
  KEY `material_categories_item_id_foreign` (`item_id`),
  KEY `idx_matcat_group` (`group_category_id`),
  KEY `material_categories_template_id_foreign` (`template_id`),
  CONSTRAINT `material_categories_group_category_id_foreign` FOREIGN KEY (`group_category_id`) REFERENCES `material_group_categories` (`id`) ON DELETE SET NULL,
  CONSTRAINT `material_categories_item_id_foreign` FOREIGN KEY (`item_id`) REFERENCES `section_items` (`id`) ON DELETE CASCADE,
  CONSTRAINT `material_categories_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `material_categories_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `material_group_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `material_group_categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_mgc_tenant_name` (`tenant_id`,`name`),
  KEY `material_group_categories_template_id_foreign` (`template_id`),
  CONSTRAINT `material_group_categories_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `material_group_categories_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `migrations`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `migrations` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `migration` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `oauth_access_tokens`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `oauth_access_tokens` (
  `id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned DEFAULT NULL,
  `client_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `scopes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `revoked` tinyint(1) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `expires_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `oauth_access_tokens_user_id_index` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `oauth_auth_codes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `oauth_auth_codes` (
  `id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `client_id` bigint unsigned NOT NULL,
  `scopes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `revoked` tinyint(1) NOT NULL,
  `expires_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `oauth_auth_codes_user_id_index` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `oauth_clients`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `oauth_clients` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `secret` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `provider` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `redirect` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `personal_access_client` tinyint(1) NOT NULL,
  `password_client` tinyint(1) NOT NULL,
  `revoked` tinyint(1) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `oauth_clients_user_id_index` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `oauth_personal_access_clients`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `oauth_personal_access_clients` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `client_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `oauth_refresh_tokens`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `oauth_refresh_tokens` (
  `id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `access_token_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `revoked` tinyint(1) NOT NULL,
  `expires_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `oauth_refresh_tokens_access_token_id_index` (`access_token_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_attic`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_attic` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `Item titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` bigint DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` bigint DEFAULT NULL,
  `video_count` bigint DEFAULT NULL,
  `material_option_count` bigint DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_cooling`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_cooling` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `Item titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` int DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` int DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` int DEFAULT NULL,
  `video_count` int DEFAULT NULL,
  `material_option_count` int DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_grounds`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_grounds` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` int DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` int DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` int DEFAULT NULL,
  `video_count` int DEFAULT NULL,
  `material_option_count` int DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_heating`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_heating` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `Item titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` bigint DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` bigint DEFAULT NULL,
  `video_count` bigint DEFAULT NULL,
  `material_option_count` bigint DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_laundry`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_laundry` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `Item titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` bigint DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` bigint DEFAULT NULL,
  `video_count` bigint DEFAULT NULL,
  `material_option_count` bigint DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `old_property_information`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `old_property_information` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_priority_id` bigint DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `media_labels` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `is_display_in_edit_report` tinyint(1) DEFAULT NULL,
  `is_display_top_in_report` tinyint(1) DEFAULT NULL,
  `priority` int DEFAULT NULL,
  `item_comment_id` bigint DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `comment_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `auto_add` tinyint(1) DEFAULT NULL,
  `sort_order` int DEFAULT NULL,
  `parent_id` bigint DEFAULT NULL,
  `option_id` bigint DEFAULT NULL,
  `image_count` int DEFAULT NULL,
  `video_count` int DEFAULT NULL,
  `material_option_count` int DEFAULT NULL,
  `is_favorite` tinyint(1) DEFAULT NULL,
  `is_comment_required_in_report` tinyint(1) DEFAULT NULL,
  `is_comment_media_required_in_report` tinyint(1) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `password_resets`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `password_resets` (
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  KEY `password_resets_email_index` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `permission_roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `permission_roles` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pid` bigint unsigned NOT NULL COMMENT 'permission id',
  `rid` bigint unsigned NOT NULL COMMENT 'role id',
  PRIMARY KEY (`id`),
  KEY `permission_roles_pid_rid_index` (`pid`,`rid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `permissions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `permissions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `menu_id` bigint unsigned DEFAULT '0',
  `p_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permission type',
  `class` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permission controller class',
  `method` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'permission controller method',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `permissions_menu_id_index` (`menu_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `priorities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `priorities` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `color_hex` varchar(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `show_description` tinyint(1) NOT NULL DEFAULT '0',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_priority_tenant_template_name` (`tenant_id`,`template_id`,`name`),
  KEY `priorities_template_id_foreign` (`template_id`),
  KEY `idx_priority_tenant_template` (`tenant_id`,`template_id`),
  CONSTRAINT `priorities_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `priorities_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `property_age_fees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `property_age_fees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `fee` decimal(10,2) NOT NULL,
  `constructed_from` int NOT NULL,
  `constructed_to` int NOT NULL,
  `sort_order` int NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `property_age_fees_tenant_id_foreign` (`tenant_id`),
  KEY `property_age_fees_service_id_foreign` (`service_id`),
  CONSTRAINT `property_age_fees_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE CASCADE,
  CONSTRAINT `property_age_fees_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `report_comments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `report_comments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `author_id` bigint unsigned NOT NULL,
  `type` enum('introduction','cover_letter','closing_statement') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'introduction',
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `auto_include_in_report` tinyint(1) NOT NULL DEFAULT '0',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_intro_tenant_title` (`tenant_id`,`title`),
  KEY `report_comments_author_id_foreign` (`author_id`),
  KEY `idx_intro_tenant_author` (`tenant_id`,`author_id`),
  KEY `report_comments_template_id_foreign` (`template_id`),
  KEY `idx_report_comments_tenant_template` (`tenant_id`,`template_id`),
  CONSTRAINT `report_comments_author_id_foreign` FOREIGN KEY (`author_id`) REFERENCES `users` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `report_comments_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `report_comments_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `report_question_options`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `report_question_options` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `question_id` bigint unsigned NOT NULL,
  `label` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_rqo_question` (`question_id`),
  CONSTRAINT `report_question_options_question_id_foreign` FOREIGN KEY (`question_id`) REFERENCES `report_questions` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `report_questions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `report_questions` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `question` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `type` enum('text','textarea','number','radio','checkbox','select','date','time','datetime') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'text',
  `show_separately` tinyint(1) NOT NULL DEFAULT '0',
  `is_required` tinyint(1) NOT NULL DEFAULT '0',
  `settings` json NOT NULL DEFAULT (json_object()),
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_rq_tenant` (`tenant_id`),
  KEY `report_questions_template_id_foreign` (`template_id`),
  CONSTRAINT `report_questions_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `report_questions_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `report_sections`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `report_sections` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `color_code` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `include_by_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to keep this section included in the report editor by default?',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_section_tenant_template_title_with_deleted_at` (`tenant_id`,`template_id`,`title`,`deleted_at`),
  KEY `report_sections_template_id_foreign` (`template_id`),
  KEY `idx_report_sections_tenant_template` (`tenant_id`,`template_id`),
  CONSTRAINT `report_sections_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `report_sections_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `report_summaries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `report_summaries` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned DEFAULT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `short_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `slug` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `color_hex` varchar(9) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `show_description` tinyint(1) NOT NULL DEFAULT '0',
  `visible_in_contractor_pricing` tinyint(1) NOT NULL DEFAULT '0',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `app_order` smallint unsigned NOT NULL DEFAULT '0',
  `report_order` smallint unsigned NOT NULL DEFAULT '0',
  `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 `uq_summary_tenant_template_name` (`tenant_id`,`template_id`,`name`),
  KEY `report_summaries_template_id_foreign` (`template_id`),
  KEY `idx_summary_tenant_template` (`tenant_id`,`template_id`),
  CONSTRAINT `report_summaries_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE SET NULL,
  CONSTRAINT `report_summaries_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `roles` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `pid` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'Parent role id',
  `user_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT 'Role created by',
  `tenant_id` bigint unsigned DEFAULT NULL COMMENT '-- NULL = system-wide role (e.g. Super Admin)',
  `user_type_id` bigint unsigned DEFAULT NULL COMMENT '-- NULL = system role, otherwise linked to Customer/Agent/Inspector',
  `title` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `role_scope` enum('system','tenant') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'tenant' COMMENT '-- Scope of role: system-wide or tenant-specific',
  `role_level` tinyint(1) NOT NULL DEFAULT '0' COMMENT '-- Is this role a level-based role?',
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_role` (`tenant_id`,`user_type_id`,`title`),
  KEY `roles_user_type_id_foreign` (`user_type_id`),
  CONSTRAINT `roles_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `roles_user_type_id_foreign` FOREIGN KEY (`user_type_id`) REFERENCES `user_types` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_additional_fees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_additional_fees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_schedule_addl_fees_schedule` (`schedule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_agents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_agents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `agent_id` bigint unsigned NOT NULL DEFAULT '0',
  `agent_type` tinyint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sa_schedule_agent` (`tenant_id`,`schedule_id`,`agent_id`,`agent_type`),
  KEY `schedule_agents_schedule_id_foreign` (`schedule_id`),
  KEY `idx_sa_tenant_schedule` (`tenant_id`,`schedule_id`),
  CONSTRAINT `schedule_agents_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_agents_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_agreements`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_agreements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned DEFAULT NULL,
  `agreement_id` bigint unsigned DEFAULT NULL,
  `service_id` bigint unsigned NOT NULL DEFAULT '0',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `state` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description_html` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_schedule_agreements_schedule` (`schedule_id`),
  KEY `idx_schedule_agreements_agreement` (`agreement_id`),
  KEY `idx_schedule_agreements_service` (`service_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_cancel_reasons`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_cancel_reasons` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned NOT NULL,
  `cancelled_by` bigint unsigned DEFAULT NULL COMMENT 'User who triggered cancellation',
  `reason` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_cancel_reasons_cancelled_by_foreign` (`cancelled_by`),
  KEY `schedule_cancel_reasons_schedule_id_index` (`schedule_id`),
  CONSTRAINT `schedule_cancel_reasons_cancelled_by_foreign` FOREIGN KEY (`cancelled_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `schedule_cancel_reasons_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_customers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_customers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `customer_id` bigint unsigned NOT NULL DEFAULT '0',
  `customer_type` tinyint unsigned NOT NULL DEFAULT '0',
  `assign_signe` tinyint unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sc_schedule_customer` (`tenant_id`,`schedule_id`,`customer_id`,`customer_type`),
  KEY `schedule_customers_schedule_id_foreign` (`schedule_id`),
  KEY `idx_sc_tenant_schedule` (`tenant_id`,`schedule_id`),
  CONSTRAINT `schedule_customers_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_customers_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_discounts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_discounts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `idx_schedule_discounts_schedule` (`schedule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_email_triggers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_email_triggers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `need_service` tinyint(1) NOT NULL DEFAULT '0',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `schedule_email_triggers_slug_unique` (`slug`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_emails`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_emails` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `trigger_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned DEFAULT NULL,
  `trigger_when` enum('before','after','on') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'after',
  `unit_type` enum('minute','hour','day') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `unit_value` smallint unsigned NOT NULL DEFAULT '0',
  `who_will_receive` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_template_id` bigint unsigned DEFAULT NULL,
  `sms_template_id` bigint unsigned DEFAULT NULL,
  `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`),
  KEY `schedule_emails_email_template_id_foreign` (`email_template_id`),
  KEY `schedule_emails_sms_template_id_foreign` (`sms_template_id`),
  KEY `schedule_emails_tenant_id_index` (`tenant_id`),
  KEY `schedule_emails_trigger_id_index` (`trigger_id`),
  KEY `schedule_emails_service_id_index` (`service_id`),
  CONSTRAINT `schedule_emails_email_template_id_foreign` FOREIGN KEY (`email_template_id`) REFERENCES `site_templates` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `schedule_emails_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `schedule_emails_sms_template_id_foreign` FOREIGN KEY (`sms_template_id`) REFERENCES `sms_templates` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `schedule_emails_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
  CONSTRAINT `schedule_emails_trigger_id_foreign` FOREIGN KEY (`trigger_id`) REFERENCES `schedule_email_triggers` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_inspectors`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_inspectors` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `previous_schedule_id` bigint unsigned DEFAULT NULL,
  `inspector_id` bigint unsigned NOT NULL DEFAULT '0',
  `is_primary` tinyint NOT NULL DEFAULT '0' COMMENT '1: primary, 0: not primary',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_si_schedule_inspector` (`tenant_id`,`schedule_id`,`inspector_id`),
  KEY `schedule_inspectors_schedule_id_foreign` (`schedule_id`),
  KEY `idx_si_tenant_schedule` (`tenant_id`,`schedule_id`),
  KEY `schedule_inspectors_previous_schedule_id_foreign` (`previous_schedule_id`),
  CONSTRAINT `schedule_inspectors_previous_schedule_id_foreign` FOREIGN KEY (`previous_schedule_id`) REFERENCES `schedules` (`id`) ON DELETE SET NULL,
  CONSTRAINT `schedule_inspectors_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_inspectors_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_payout_amounts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_payout_amounts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_payout_id` bigint unsigned NOT NULL,
  `calculated_payout` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'System calculated payout amount',
  `new_amount` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Adjusted/final payout amount',
  `note` text COLLATE utf8mb4_unicode_ci COMMENT 'Notes or reason for payout adjustment',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_payout_amounts_schedule_payout_id_index` (`schedule_payout_id`),
  CONSTRAINT `schedule_payout_amounts_schedule_payout_id_foreign` FOREIGN KEY (`schedule_payout_id`) REFERENCES `schedule_payouts` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_payouts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_payouts` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `inspector_id` bigint unsigned NOT NULL,
  `service_total_fee` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Total fee for the service',
  `pay_type` enum('fixed','percentage','hourly') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'fixed' COMMENT 'Type of payment calculation',
  `amount_per_inspection` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Amount paid to inspector per inspection',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_payouts_schedule_id_foreign` (`schedule_id`),
  KEY `schedule_payouts_tenant_id_schedule_id_index` (`tenant_id`,`schedule_id`),
  KEY `schedule_payouts_inspector_id_schedule_id_index` (`inspector_id`,`schedule_id`),
  KEY `schedule_payouts_service_id_index` (`service_id`),
  CONSTRAINT `schedule_payouts_inspector_id_foreign` FOREIGN KEY (`inspector_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_payouts_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_payouts_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_payouts_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_property_details`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_property_details` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `search_location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address_line1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address_line2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `postal_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `square_feet` int unsigned DEFAULT NULL,
  `year_built` smallint unsigned DEFAULT NULL,
  `bedrooms` tinyint unsigned DEFAULT NULL,
  `bathrooms` decimal(4,1) DEFAULT NULL,
  `inspection_note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `latitude` decimal(10,7) DEFAULT NULL,
  `longitude` decimal(10,7) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_property_details_schedule_id_foreign` (`schedule_id`),
  KEY `idx_spd_tenant_schedule` (`tenant_id`,`schedule_id`),
  CONSTRAINT `schedule_property_details_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_property_details_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_services`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_services` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `schedule_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `report_template_id` bigint unsigned NOT NULL DEFAULT '0',
  `quantity` int unsigned NOT NULL DEFAULT '1',
  `service_fee` decimal(10,2) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_services_service_id_foreign` (`service_id`),
  KEY `idx_ss_tenant_schedule` (`tenant_id`,`schedule_id`),
  KEY `idx_ss_schedule_service` (`schedule_id`,`service_id`),
  CONSTRAINT `schedule_services_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_services_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `schedule_services_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedule_time_hold_reason`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedule_time_hold_reason` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `schedule_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL,
  `created_by` bigint unsigned NOT NULL,
  `reason` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `held_at` timestamp NOT NULL,
  `released_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `schedule_time_hold_reason_created_by_foreign` (`created_by`),
  KEY `schedule_time_hold_reason_schedule_id_is_active_index` (`schedule_id`,`is_active`),
  KEY `schedule_time_hold_reason_tenant_id_index` (`tenant_id`),
  CONSTRAINT `schedule_time_hold_reason_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_time_hold_reason_schedule_id_foreign` FOREIGN KEY (`schedule_id`) REFERENCES `schedules` (`id`) ON DELETE CASCADE,
  CONSTRAINT `schedule_time_hold_reason_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `schedules`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `schedules` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `appointment_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '1=Step1 Created, 2=Step2 People Added, 3=Complete, 4=Empty Available Slot',
  `is_cancelled` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '0: active, 1: cancelled',
  `is_on_hold` tinyint NOT NULL DEFAULT '0' COMMENT '0=Not On Hold, 1=On Hold',
  `is_time_off` tinyint(1) NOT NULL DEFAULT '0' COMMENT '1: time off, 0: not time off',
  `created_by` bigint NOT NULL DEFAULT '0',
  `is_payment_done` tinyint NOT NULL DEFAULT '0' COMMENT '0 = not paid, 1 = paid',
  `is_report_submitted` tinyint(1) NOT NULL DEFAULT '0',
  `submitted_by` bigint unsigned DEFAULT NULL,
  `submitted_at` timestamp NULL DEFAULT NULL,
  `scheduled_date` date NOT NULL,
  `start_time` time NOT NULL,
  `adjusted_time` time DEFAULT NULL,
  `entered_by` int unsigned DEFAULT NULL,
  `referral_source` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `inspection_type_id` bigint unsigned DEFAULT NULL,
  `foundation_type_id` bigint unsigned DEFAULT NULL,
  `preferred_language` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `occupied_status` enum('yes','no','unsure') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unsure',
  `utilities_status` enum('yes','no','unsure') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'unsure',
  `total_fee` decimal(10,2) DEFAULT '0.00',
  `invoice_note` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `insurance_carrier` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `widget_visiable` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `restore_date` timestamp NULL DEFAULT NULL COMMENT 'When a cancelled schedule was restored',
  `reschedule_date` timestamp NULL DEFAULT NULL COMMENT 'When the schedule was re-scheduled (similar to restore_date)',
  PRIMARY KEY (`id`),
  UNIQUE KEY `schedules_appointment_id_unique` (`appointment_id`),
  KEY `schedules_inspection_type_id_foreign` (`inspection_type_id`),
  KEY `schedules_foundation_type_id_foreign` (`foundation_type_id`),
  KEY `idx_schedule_tenant_date` (`tenant_id`,`scheduled_date`),
  KEY `schedules_submitted_by_foreign` (`submitted_by`),
  CONSTRAINT `schedules_foundation_type_id_foreign` FOREIGN KEY (`foundation_type_id`) REFERENCES `foundation_types` (`id`) ON DELETE SET NULL,
  CONSTRAINT `schedules_inspection_type_id_foreign` FOREIGN KEY (`inspection_type_id`) REFERENCES `inspection_types` (`id`) ON DELETE SET NULL,
  CONSTRAINT `schedules_submitted_by_foreign` FOREIGN KEY (`submitted_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `schedules_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_column_exclusions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_column_exclusions` (
  `section_id` bigint unsigned NOT NULL,
  `column_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`section_id`,`column_id`),
  KEY `section_column_exclusions_column_id_foreign` (`column_id`),
  CONSTRAINT `section_column_exclusions_column_id_foreign` FOREIGN KEY (`column_id`) REFERENCES `section_columns` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_column_exclusions_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `report_sections` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_columns`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_columns` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `abbreviation` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `comment_color` char(7) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `is_column_printable` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to make this column as printable in reports? \n',
  `is_info_printable` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to make this column information as printable in reports? \n        ',
  `is_comment_required` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to make comments as required for this column?',
  `enabled_by_default` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to keep this status as enabled by default in report? \n    ',
  `selects_other_statuses` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to keep other status as selected with this status? \n',
  `remove_item_when_selected` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Do you want to remove item when this status will be selected? \n',
  `is_defect_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Is this status related to defects? \n',
  `is_not_inspected_or_np` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Is this status related to not inspected or not present? \n',
  `icon_source` enum('system','library') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_tenant_section_name` (`tenant_id`,`name`),
  KEY `idx_tenant` (`tenant_id`),
  CONSTRAINT `section_columns_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_comments`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_comments` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `category_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `priority_id` bigint unsigned DEFAULT NULL,
  `master_language_id` bigint unsigned DEFAULT NULL,
  `summary_ids` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `display_in_editor` tinyint(1) NOT NULL DEFAULT '0',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `meta` json NOT NULL DEFAULT (json_object()),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_comment_tenant_cat_title_with_deleted_at` (`tenant_id`,`category_id`,`title`,`deleted_at`),
  KEY `section_comments_category_id_foreign` (`category_id`),
  KEY `section_comments_priority_id_foreign` (`priority_id`),
  KEY `section_comments_master_language_id_foreign` (`master_language_id`),
  CONSTRAINT `section_comments_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `section_item_categories` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `section_comments_master_language_id_foreign` FOREIGN KEY (`master_language_id`) REFERENCES `master_languages` (`id`) ON DELETE SET NULL,
  CONSTRAINT `section_comments_priority_id_foreign` FOREIGN KEY (`priority_id`) REFERENCES `priorities` (`id`) ON DELETE SET NULL,
  CONSTRAINT `section_comments_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_item_categories`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_item_categories` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `section_id` bigint unsigned NOT NULL,
  `item_id` bigint unsigned NOT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `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 `uq_item_category_per_item_title_with_deleted_at` (`tenant_id`,`section_id`,`item_id`,`title`,`deleted_at`),
  KEY `section_item_categories_section_id_foreign` (`section_id`),
  KEY `section_item_categories_item_id_foreign` (`item_id`),
  CONSTRAINT `section_item_categories_item_id_foreign` FOREIGN KEY (`item_id`) REFERENCES `section_items` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_item_categories_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `report_sections` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_item_categories_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_item_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_item_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `section_id` bigint unsigned NOT NULL,
  `type_id` bigint unsigned NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_item_type_per_section_title` (`tenant_id`,`section_id`,`type_id`),
  KEY `section_item_types_section_id_foreign` (`section_id`),
  KEY `section_item_types_type_id_foreign` (`type_id`),
  CONSTRAINT `section_item_types_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `report_sections` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_item_types_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_item_types_type_id_foreign` FOREIGN KEY (`type_id`) REFERENCES `item_types` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `section_items`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `section_items` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `created_by` bigint unsigned DEFAULT NULL COMMENT 'User who originally created the item',
  `section_id` bigint unsigned NOT NULL,
  `item_type_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `default_section_column_id` bigint unsigned DEFAULT NULL,
  `defect_type_id` bigint unsigned DEFAULT NULL,
  `is_required` tinyint(1) NOT NULL DEFAULT '0' COMMENT '\nIs this required item to be shown in report for inspection?',
  `display_in_editor` tinyint(1) NOT NULL DEFAULT '0' COMMENT '\nDo you want this item to display in report editor?',
  `settings` json NOT NULL DEFAULT (json_object()),
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_item_per_section_title_with_deleted_at` (`tenant_id`,`section_id`,`title`,`deleted_at`),
  KEY `section_items_default_section_column_id_foreign` (`default_section_column_id`),
  KEY `section_items_defect_type_id_foreign` (`defect_type_id`),
  KEY `idx_section` (`section_id`),
  CONSTRAINT `section_items_default_section_column_id_foreign` FOREIGN KEY (`default_section_column_id`) REFERENCES `section_columns` (`id`) ON DELETE SET NULL,
  CONSTRAINT `section_items_defect_type_id_foreign` FOREIGN KEY (`defect_type_id`) REFERENCES `defect_types` (`id`) ON DELETE SET NULL,
  CONSTRAINT `section_items_section_id_foreign` FOREIGN KEY (`section_id`) REFERENCES `report_sections` (`id`) ON DELETE CASCADE,
  CONSTRAINT `section_items_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_area_distance_fees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_area_distance_fees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `policy_id` bigint unsigned NOT NULL,
  `origin` enum('office','employee') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'employee',
  `inspector_user_id` bigint unsigned DEFAULT NULL,
  `from_miles` decimal(6,2) NOT NULL DEFAULT '0.00',
  `to_miles` decimal(6,2) DEFAULT NULL,
  `extra_fee` decimal(10,2) NOT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `inspector_key` bigint unsigned GENERATED ALWAYS AS ((case when (`origin` = _utf8mb4'employee') then `inspector_user_id` else 0 end)) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sadf_range` (`policy_id`,`origin`,`inspector_key`,`from_miles`,`to_miles`),
  KEY `fk_sadf_inspector` (`inspector_user_id`),
  CONSTRAINT `fk_sadf_inspector` FOREIGN KEY (`inspector_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_sadf_policy` FOREIGN KEY (`policy_id`) REFERENCES `service_area_policies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_area_inspector_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_area_inspector_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `policy_id` bigint unsigned NOT NULL,
  `inspector_user_id` bigint unsigned NOT NULL,
  `free_miles_override` decimal(6,2) DEFAULT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sais_unique` (`policy_id`,`inspector_user_id`),
  KEY `fk_sais_inspector` (`inspector_user_id`),
  CONSTRAINT `fk_sais_inspector` FOREIGN KEY (`inspector_user_id`) REFERENCES `users` (`id`),
  CONSTRAINT `fk_sais_policy` FOREIGN KEY (`policy_id`) REFERENCES `service_area_policies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_area_policies`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_area_policies` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `mode` enum('by_zip_code','office_location','employee_location','fixed_charge','no_charge') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'employee_location',
  `free_miles` decimal(6,2) NOT NULL DEFAULT '0.00' COMMENT 'no charge up to this distance',
  `fixed_extra_fee` decimal(10,2) DEFAULT NULL COMMENT 'used when mode = FIXED_CHARGE',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sap_tenant` (`tenant_id`),
  CONSTRAINT `service_area_policies_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_area_zip_fees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_area_zip_fees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `policy_id` bigint unsigned NOT NULL,
  `zip_code` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `extra_fee` decimal(10,2) NOT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sazf` (`policy_id`,`zip_code`),
  CONSTRAINT `fk_sazf_policy` FOREIGN KEY (`policy_id`) REFERENCES `service_area_policies` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_fees`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_fees` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `service_id` bigint unsigned NOT NULL,
  `condo_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'For condo fee type: bedroom or bathroom',
  `unit` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Multihouse unit label',
  `mins` int NOT NULL,
  `sqft_from` int NOT NULL,
  `sqft_to` int NOT NULL,
  `fee` decimal(10,2) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `service_fees_service_id_foreign` (`service_id`),
  CONSTRAINT `service_fees_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `service_pay_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_pay_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `pay_type` enum('hourly','fixed','percentage') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pay_difference` decimal(10,2) NOT NULL DEFAULT '0.00',
  `amount_per_inspection` decimal(10,2) DEFAULT NULL,
  `inspection_from` enum('company','personal') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'company',
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `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 `uq_tenant_user_service` (`tenant_id`,`user_id`,`service_id`),
  KEY `service_pay_settings_user_id_foreign` (`user_id`),
  KEY `service_pay_settings_service_id_foreign` (`service_id`),
  CONSTRAINT `service_pay_settings_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE CASCADE,
  CONSTRAINT `service_pay_settings_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `service_pay_settings_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `services`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `services` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `service_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `service_type` enum('Residential','Sewer','Radon','Other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fee_type` enum('Fixed','Condo','Multihouse','Variable','Quotation') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Fixed',
  `base_fee` decimal(10,2) NOT NULL DEFAULT '0.00',
  `base_sqft` decimal(10,2) NOT NULL DEFAULT '0.00',
  `fee_per_sqft` decimal(10,2) NOT NULL DEFAULT '0.00',
  `fee` decimal(10,2) NOT NULL DEFAULT '0.00',
  `sort_order` int NOT NULL DEFAULT '0',
  `is_main_service` tinyint(1) NOT NULL DEFAULT '0',
  `hide_in_scheduler` tinyint(1) NOT NULL DEFAULT '0',
  `include_fees_per_service_area` tinyint(1) NOT NULL DEFAULT '0',
  `add_quantity` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Like more than one mold sample',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `duration` int NOT NULL DEFAULT '0',
  `short_name_of_service` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `default_inspector_id` bigint unsigned DEFAULT NULL,
  `master_language_id` bigint unsigned DEFAULT NULL,
  `default_template_id` bigint unsigned DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `services_tenant_id_foreign` (`tenant_id`),
  KEY `services_default_inspector_id_foreign` (`default_inspector_id`),
  KEY `services_master_language_id_foreign` (`master_language_id`),
  CONSTRAINT `services_default_inspector_id_foreign` FOREIGN KEY (`default_inspector_id`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `services_master_language_id_foreign` FOREIGN KEY (`master_language_id`) REFERENCES `master_languages` (`id`) ON DELETE SET NULL,
  CONSTRAINT `services_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `site_contents`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `site_contents` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `slug` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `short_description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci,
  `long_description` longtext CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci,
  `meta_title` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `meta_keyword` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `meta_description` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `site_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `site_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `is_visible` tinyint unsigned NOT NULL DEFAULT '1' COMMENT 'Is visible in the api response?',
  `is_required` tinyint unsigned DEFAULT '1',
  `is_encrypted` tinyint unsigned DEFAULT '0',
  `key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `val` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci,
  `field_label` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT 'Field printable name',
  `field_type` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '1=Textbox, 2=Textarea, 3=Email, 4=Number, 5=Dropdown, 6=Radio, 7=Checkbox, 8=Password, 9=File, 10=Switch',
  `field_options` json DEFAULT NULL COMMENT 'Option for Dropdown, Radio, Checkbox',
  `group_name` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'general',
  `help_text` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `site_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `site_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL DEFAULT '0',
  `master_language_id` bigint unsigned DEFAULT NULL,
  `status` tinyint unsigned NOT NULL DEFAULT '1',
  `template_type` tinyint unsigned NOT NULL DEFAULT '1' COMMENT '1 = Email, 2 = SMS, 3 = PDF',
  `pdf_paper_size` tinyint unsigned NOT NULL DEFAULT '4' COMMENT '0 = A0, 1 = A1, 2 = A2, and so on.',
  `pdf_paper_layout` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '0 = Portrait, 1 = Landscape',
  `template_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `subject` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `site_templates_master_language_id_index` (`master_language_id`),
  CONSTRAINT `site_templates_master_language_id_foreign` FOREIGN KEY (`master_language_id`) REFERENCES `master_languages` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `sms_templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `sms_templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned DEFAULT NULL,
  `master_language_id` bigint unsigned DEFAULT NULL,
  `title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `event_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `is_enabled` tinyint(1) NOT NULL DEFAULT '1',
  `meta` json NOT NULL DEFAULT (json_object()),
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_sms_tenant_title` (`tenant_id`,`title`),
  UNIQUE KEY `uq_sms_tenant_event` (`tenant_id`,`event_key`),
  KEY `sms_templates_master_language_id_index` (`master_language_id`),
  CONSTRAINT `sms_templates_master_language_id_foreign` FOREIGN KEY (`master_language_id`) REFERENCES `master_languages` (`id`) ON DELETE CASCADE,
  CONSTRAINT `sms_templates_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `sponsors`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `sponsors` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL DEFAULT '0',
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `status` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `sponsors_tenant_id_index` (`tenant_id`),
  CONSTRAINT `sponsors_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `taxes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `taxes` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned DEFAULT NULL,
  `title` varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `tax_type` enum('Percentage','Fixed') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `tax_rate` decimal(9,4) NOT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `service_key` bigint unsigned GENERATED ALWAYS AS (ifnull(`service_id`,0)) STORED,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_taxes_agency_service_title` (`tenant_id`,`service_key`,`title`),
  CONSTRAINT `taxes_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `template_old_data`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `template_old_data` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `inspection_template_id` bigint DEFAULT NULL,
  `template_section_id` bigint DEFAULT NULL,
  `template_parent_section_id` bigint DEFAULT NULL,
  `section_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `template_section_item_id` bigint DEFAULT NULL,
  `item_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `item_titles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `inspect_action` int DEFAULT NULL,
  `is_automatically_added` tinyint(1) DEFAULT NULL,
  `is_included` tinyint(1) DEFAULT NULL,
  `sort_order` int DEFAULT NULL,
  `external_link` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `display_records` int DEFAULT NULL,
  `item_defect_type` int DEFAULT NULL,
  `item_category_id` bigint DEFAULT NULL,
  `category_id` bigint DEFAULT NULL,
  `template_section_item_id_category` bigint DEFAULT NULL,
  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `template_services`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `template_services` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `template_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_template_service` (`tenant_id`,`template_id`,`service_id`),
  KEY `template_services_service_id_foreign` (`service_id`),
  KEY `idx_template_service` (`template_id`,`service_id`),
  CONSTRAINT `template_services_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE RESTRICT,
  CONSTRAINT `template_services_template_id_foreign` FOREIGN KEY (`template_id`) REFERENCES `templates` (`id`) ON DELETE CASCADE,
  CONSTRAINT `template_services_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `templates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `templates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `template_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'General',
  `structure_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Section by Section',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `is_default` tinyint(1) NOT NULL DEFAULT '0',
  `sort_order` int NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `templates_slug_unique` (`slug`),
  KEY `templates_tenant_id_foreign` (`tenant_id`),
  CONSTRAINT `templates_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tenant_settings`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tenant_settings` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `key` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `val` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci,
  `field_label` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uq_tenant_setting_key` (`tenant_id`,`key`),
  KEY `tenant_settings_key_index` (`key`),
  CONSTRAINT `tenant_settings_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `tenants`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `tenants` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `company_phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `website_url` varchar(2083) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address_line1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `address_line2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `city` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `state` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `postal` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `country` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `facebook_review_url` varchar(2083) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `google_review_url` varchar(2083) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `yelp_review_url` varchar(2083) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `slogan_tagline` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `standard_type` enum('Ashi','INTERNACHI','Other') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `timezone` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'UTC' COMMENT 'IANA TZ (e.g. America/Chicago)',
  `work_start_time` time NOT NULL DEFAULT '08:00:00',
  `work_end_time` time NOT NULL DEFAULT '18:00:00',
  `work_days_mask` tinyint unsigned NOT NULL DEFAULT '127' COMMENT '7-bit mask: bit0=Sun ... bit6=Sat',
  `radon_start_time` time DEFAULT NULL,
  `radon_end_time` time DEFAULT NULL,
  `radon_days_mask` tinyint unsigned DEFAULT NULL COMMENT 'NULL => use work_days_mask',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `tenants_slug_unique` (`slug`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availabilities`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availabilities` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `tenant_id` bigint unsigned NOT NULL,
  `user_id` bigint unsigned NOT NULL,
  `service_id` bigint unsigned DEFAULT NULL,
  `rule_type` enum('by_day','by_date_weekly','by_date_monthly','by_date_custom') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `start_time` time NOT NULL,
  `end_time` time DEFAULT NULL,
  `sort_order` int unsigned NOT NULL DEFAULT '0',
  `is_active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_availabilities_service_id_foreign` (`service_id`),
  KEY `idx_tenant_user` (`tenant_id`,`user_id`),
  KEY `idx_user_service` (`user_id`,`service_id`),
  CONSTRAINT `user_availabilities_service_id_foreign` FOREIGN KEY (`service_id`) REFERENCES `services` (`id`) ON DELETE CASCADE,
  CONSTRAINT `user_availabilities_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE,
  CONSTRAINT `user_availabilities_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availability_custom_dates`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availability_custom_dates` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `availability_id` bigint unsigned NOT NULL,
  `date_on` date NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_uacd_av` (`availability_id`),
  CONSTRAINT `user_availability_custom_dates_availability_id_foreign` FOREIGN KEY (`availability_id`) REFERENCES `user_availabilities` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availability_custom_ranges`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availability_custom_ranges` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `availability_id` bigint unsigned NOT NULL,
  `date_from` date NOT NULL,
  `date_to` date NOT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_uacr_av` (`availability_id`),
  CONSTRAINT `user_availability_custom_ranges_availability_id_foreign` FOREIGN KEY (`availability_id`) REFERENCES `user_availabilities` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availability_days`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availability_days` (
  `availability_id` bigint unsigned NOT NULL,
  `days_mask` tinyint unsigned NOT NULL DEFAULT '127' COMMENT 'bit0=Sun ... bit6=Sat',
  PRIMARY KEY (`availability_id`),
  CONSTRAINT `user_availability_days_availability_id_foreign` FOREIGN KEY (`availability_id`) REFERENCES `user_availabilities` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availability_monthly`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availability_monthly` (
  `availability_id` bigint unsigned NOT NULL,
  `months_mask` smallint unsigned NOT NULL COMMENT 'bit0=Jan ... bit11=Dec',
  `month_days` json NOT NULL DEFAULT (json_array()),
  PRIMARY KEY (`availability_id`),
  CONSTRAINT `user_availability_monthly_availability_id_foreign` FOREIGN KEY (`availability_id`) REFERENCES `user_availabilities` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_availability_weekly`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_availability_weekly` (
  `availability_id` bigint unsigned NOT NULL,
  `week_numbers_mask` tinyint unsigned NOT NULL COMMENT 'bit0=W1 .. bit5=W6',
  `week_days_mask` tinyint unsigned NOT NULL COMMENT 'bit0=Sun ... bit6=Sat',
  PRIMARY KEY (`availability_id`),
  CONSTRAINT `user_availability_weekly_availability_id_foreign` FOREIGN KEY (`availability_id`) REFERENCES `user_availabilities` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_roles`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_roles` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` bigint unsigned NOT NULL,
  `role_id` bigint unsigned NOT NULL,
  `tenant_id` bigint unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `user_roles_user_id_foreign` (`user_id`),
  KEY `user_roles_role_id_foreign` (`role_id`),
  CONSTRAINT `user_roles_role_id_foreign` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE,
  CONSTRAINT `user_roles_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `user_types`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_types` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `users` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0 => registered, 1 => active, 2 => blocked',
  `name_initial_color_type` tinyint(1) DEFAULT '1',
  `verified` tinyint(1) NOT NULL DEFAULT '0',
  `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'username',
  `name_initials` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `first_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `last_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `secondary_email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `phone` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `fax` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `note` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci,
  `mobile` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `discount_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `remember_token` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `notification_preference` enum('email','sms','both') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `email_verified_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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (1,'2014_10_12_000000_create_users_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (2,'2014_10_12_100000_create_password_resets_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (3,'2016_06_01_000001_create_oauth_auth_codes_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (4,'2016_06_01_000002_create_oauth_access_tokens_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (5,'2016_06_01_000003_create_oauth_refresh_tokens_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (6,'2016_06_01_000004_create_oauth_clients_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (7,'2016_06_01_000005_create_oauth_personal_access_clients_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (8,'2019_08_19_000000_create_failed_jobs_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (9,'2020_04_03_111606_create_admin_menus',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (10,'2020_04_03_124408_create_cdns',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (11,'2020_04_03_124618_create_files',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (12,'2020_04_03_125952_create_permissions',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (13,'2020_04_03_130441_create_permission_roles',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (14,'2020_04_03_130600_create_tenant_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (15,'2020_04_03_130601_create_user_type_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (16,'2020_04_03_130608_create_roles',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (17,'2020_04_03_131044_create_site_contents',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (18,'2020_04_03_131512_create_site_templates',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (19,'2020_04_03_135315_create_site_settings',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (20,'2020_04_03_140502_create_user_roles',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (21,'2020_10_22_152932_create_error_logs_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (22,'2025_08_18_123958_create_inspector_profiles_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (23,'2025_08_18_143500_create_service_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (24,'2025_08_18_143541_create_agreements_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (25,'2025_08_18_144941_create_agreement_versions_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (26,'2025_08_18_154134_create_service_area_policies_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (27,'2025_08_18_155203_create_service_area_inspector_settings_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (28,'2025_08_18_162001_create_service_area_distance_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (29,'2025_08_18_163235_create_service_area_zip_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (30,'2025_08_19_052538_create_taxes_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (31,'2025_08_19_061257_create_client_discounts_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (32,'2025_08_19_135721_add_field_name_to_tenant_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (33,'2025_08_19_142510_add_company_profile_field_to_tenant_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (34,'2025_08_20_052626_create_agency_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (35,'2025_08_20_053406_create_agency_membership_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (36,'2025_08_20_104322_add_field_name_to_user_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (37,'2025_08_20_105146_create_address_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (38,'2025_08_20_110242_create_inspector_association_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (39,'2025_08_20_111518_add_secondary_email_mobile_field_to_user_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (40,'2025_08_20_111941_add_fax_note_field_to_user_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (41,'2025_08_20_114654_create_service_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (42,'2025_08_20_120652_create_property_age_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (43,'2025_08_20_130004_create_discount_coupon_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (44,'2025_08_20_131012_create_discount_coupon_service_rule_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (45,'2025_08_20_133818_add_tenant_id_field_to_site_template_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (46,'2025_08_20_144044_create_customer_agent_type_options_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (47,'2025_08_23_113610_add_tenant_id_to_user_role_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (48,'2025_08_25_110120_add_latitude_longitude_in_addresses_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (49,'2025_08_27_000001_update_services_table_add_fee_options',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (50,'2025_08_27_000002_create_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (51,'2025_08_29_082355_add_updated_at_field_to_agreement_version_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (52,'2025_08_30_055222_add_deleted_at_to_property_age_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (53,'2025_09_01_122814_update_discount_coupons_table_remove_description_add_change_service_price',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (54,'2025_09_01_142011_create_sms_template_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (55,'2025_09_01_150549_add_soft_deletes_to_sms_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (56,'2025_09_02_070520_create_customer_agent_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (57,'2025_09_04_122933_update_property_age_fees_triggers_ignore_soft_deleted',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (58,'2025_09_04_123221_create_sponsors_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (59,'2025_09_04_124353_create_association_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (60,'2025_09_04_132043_add_display_in_profile_to_inspector_associations_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (61,'2025_09_05_060308_create_service_pay_settings_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (62,'2025_09_05_063100_create_user_availability_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (63,'2025_09_05_073406_create_section_column_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (64,'2025_09_05_080434_create_report_section_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (65,'2025_09_05_092428_create_section_item_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (66,'2025_09_05_102835_create_item_type_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (67,'2025_09_05_102837_create_section_item_type_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (68,'2025_09_05_110927_create_section_item_category_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (69,'2025_09_05_115645_add_latitude_longitude_to_agencies_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (70,'2025_09_05_121543_make_settings_nullable_in_customer_agent_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (71,'2025_09_05_124108_add_sort_order_field_to_section_item_type_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (72,'2025_09_05_130631_create_comment_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (73,'2025_09_05_142324_update_user_availability_days_mask_default',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (74,'2025_09_05_144358_create_material_category_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (75,'2025_09_05_151532_create_report_introduction_comment_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (76,'2025_09_05_152632_add_type_field_to_report_comment_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (77,'2025_09_05_153724_create_report_question_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (78,'2025_09_05_162057_create_attachment_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (79,'2025_09_06_000000_create_foundation_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (80,'2025_09_06_000000_create_inspection_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (81,'2025_09_06_000001_create_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (82,'2025_09_06_000002_create_schedule_property_details_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (83,'2025_09_06_000003_create_schedule_services_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (84,'2025_09_06_000004_create_schedule_inspectors_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (85,'2025_09_06_000005_create_schedule_customers_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (86,'2025_09_06_000006_create_schedule_agents_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (87,'2025_09_06_030307_create_priority_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (88,'2025_09_06_032045_add_field_name_to_section_comment_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (89,'2025_09_06_033820_create_report_summary_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (90,'2025_09_08_135923_force_drop_unique_constraint_service_pay_settings',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (91,'2025_09_09_143227_add_remove_field_name_to_template_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (92,'2025_09_09_151546_add_template_id_field_to_report_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (93,'2025_09_09_153143_add_template_id_field_to_report_section_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (94,'2025_09_10_115741_add_is_default_to_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (95,'2025_09_12_124328_add_template_id_to_report_questions_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (96,'2025_09_13_021439_remove_meta_column_from_priorities_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (97,'2025_09_13_022435_remove_meta_column_from_report_summaries_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (98,'2025_09_15_000000_add_created_by_to_section_items_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (99,'2025_09_15_060043_add_template_id_in_attachments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (100,'2025_09_15_074958_add_soft_deletes_to_attachments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (101,'2025_09_16_011906_add_deleted_at_to_report_sections_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (102,'2025_09_16_052821_create_master_languages_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (103,'2025_09_16_062400_add_sort_order_to_item_types_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (104,'2025_09_16_064333_add_master_language_id_in_site_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (105,'2025_09_16_064409_add_master_language_id_in_sms_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (106,'2025_09_16_133450_add_template_id_to_material_categories_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (107,'2025_09_16_133502_add_template_id_to_material_group_categories_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (108,'2025_09_17_000001_add_quantity_to_schedule_services_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (109,'2025_09_17_133248_add_deleted_at_to_material_categories_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (110,'2025_09_17_133254_add_deleted_at_to_material_group_categories_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (111,'2025_09_18_000007_add_status_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (112,'2025_09_18_000020_create_schedule_email_triggers_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (113,'2025_09_18_000021_create_schedule_emails_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (114,'2025_09_18_155536_update_material_categories_unique_constraint_with_deleted_at',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (115,'2025_09_19_000001_add_slug_to_schedule_email_triggers_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (116,'2025_09_19_000001_create_schedule_discounts_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (117,'2025_09_19_000002_create_schedule_additional_fees_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (118,'2025_09_19_000003_create_schedule_agreements_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (119,'2025_09_19_000010_add_billing_fields_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (120,'2025_09_24_000000_add_is_payment_done_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (121,'2025_09_25_000001_add_create_by_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (122,'2025_10_03_000000_create_comment_diy_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (123,'2025_10_03_010000_add_type_to_comment_diy_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (124,'2025_10_06_000000_add_cancel_restore_fields_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (125,'2025_10_07_095935_add_master_language_id_to_agreements_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (126,'2025_10_08_000001_add_service_id_to_schedule_agreements_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (127,'2025_10_08_000100_add_reschedule_data_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (128,'2025_10_08_055301_create_inspector_time_off_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (129,'2025_10_09_000000_create_invoice_notes_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (130,'2025_10_11_074054_update_inspector_time_off_table_add_time_off_fields',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (131,'2025_10_11_100001_create_invoices_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (132,'2025_10_11_100002_create_invoice_contacts_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (133,'2025_10_11_100003_create_invoice_payments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (134,'2025_10_14_052644_fix_service_area_distance_fees_constraint',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (135,'2025_10_16_095803_add_slot_column_and_status_comment_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (136,'2025_10_16_120924_add_is_on_hold_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (137,'2025_10_22_000001_add_service_fee_to_schedule_services_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (138,'2025_10_22_064422_add_adjusted_time_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (139,'2025_10_22_080825_create_schedule_time_hold_reason_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (140,'2025_10_22_120024_add_master_language_id_to_services_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (141,'2025_10_22_135820_add_master_language_id_to_section_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (142,'2025_10_24_120000_create_employee_time_offs_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (143,'2025_10_27_000000_add_bookmark_favourite_to_section_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (144,'2025_10_28_000001_add_is_primary_to_schedule_inspectors_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (145,'2025_10_28_062810_add_is_time_off_to_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (146,'2025_10_28_120000_remove_bookmark_favourite_from_section_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (147,'2025_10_28_130000_create_comment_bookmarks_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (148,'2025_10_28_130001_create_comment_favourites_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (149,'2025_10_29_150000_create_schedule_cancel_reasons_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (150,'2025_10_29_151000_seed_schedule_cancel_email_template',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (151,'2025_10_30_000001_create_inspector_time_off_schedules_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (152,'2025_10_31_000000_create_inspection_templates_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (153,'2025_10_31_000001_create_inspection_users_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (154,'2025_10_31_000002_create_inspection_report_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (155,'2025_10_31_000003_create_inspection_report_questions_tables',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (156,'2025_10_31_000004_create_inspection_attachments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (157,'2025_10_31_000005_create_inspection_section_related_tables',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (158,'2025_10_31_120000_add_type_to_inspection_report_comments_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (159,'2025_11_03_000001_rename_msater_question_id_column',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (160,'2025_11_03_000002_create_inspection_comment_diy_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (161,'2025_11_03_000003_add_template_id_to_inspection_report_sections_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (162,'2025_11_03_000004_add_deleted_at_to_inspection_report_sections_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (163,'2025_11_04_120000_create_customer_agent_mappings_table',1);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (164,'2025_11_05_000006_update_inspection_report_sections_template_fk_to_inspection_templates',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (165,'2025_11_05_000007_drop_section_related_columns_from_inspection_report_comments',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (166,'2025_11_05_000008_add_inspection_template_columns_to_inspection_report_comments',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (167,'2025_11_05_000009_add_inspection_template_id_to_inspection_attachments',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (168,'2025_11_05_000010_rename_template_id_in_inspection_report_sections',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (169,'2025_11_05_000011_drop_inspection_section_item_types_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (170,'2025_11_06_000001_create_agent_sponsors_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (171,'2025_11_08_082349_drop_comment_bookmarks_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (172,'2025_11_08_082608_drop_comment_favourites_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (173,'2025_11_08_082836_create_comment_bookmarks_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (174,'2025_11_08_082928_create_comment_favourites_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (175,'2025_11_08_085337_add_columns_to_inspection_material_categories_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (176,'2025_11_09_055941_add_master_item_id_to_inspection_item_types_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (177,'2025_11_09_061659_create_inspection_item_files_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (178,'2025_11_10_073003_create_inspection_section_files_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (179,'2025_11_10_084445_create_inspection_item_bookmarks_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (180,'2025_11_10_140715_add_status_columns_to_inspection_section_items_table',2);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (181,'2025_11_10_062640_add_is_report_submitted_to_schedules_table',3);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (182,'2025_11_11_151917_drop_status_columns_from_inspection_section_items_table',4);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (183,'2025_11_11_152723_add_item_status_to_inspection_section_items_table',4);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (184,'2025_11_12_075449_create_template_old_data_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (185,'2025_11_12_081315_create_old_property_information_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (186,'2025_11_12_081805_create_old_grounds_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (187,'2025_11_12_082219_create_old_cooling_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (188,'2025_11_12_083022_create_old_heating_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (189,'2025_11_12_083342_create_old_laundry_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (190,'2025_11_12_083716_create_old_attic_table',5);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (191,'2025_11_17_060020_add_previous_schedule_id_to_schedule_inspectors_table',6);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (192,'2025_11_17_130500_drop_sort_order_is_active_from_inspection_report_question_options_table',7);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (193,'2025_11_17_131000_add_template_and_option_ids_to_inspection_report_question_options_table',7);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (194,'2025_11_17_140000_drop_inspection_report_question_options_table',7);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (195,'2025_11_17_150000_create_inspection_report_question_options_table',7);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (196,'2025_11_17_151600_update_unique_index_on_inspection_report_sections',7);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (197,'2025_11_18_000001_add_master_category_id_to_inspection_section_item_categories_table',8);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (198,'2025_11_20_061126_add_condo_type_column_to_service_fees_table',9);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (199,'2025_11_20_100050_update_services_fee_type_enum',9);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (200,'2025_11_24_120001_add_unit_column_to_service_fees_table',10);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (201,'2025_11_27_000000_add_is_duplicate_to_inspection_material_categories_table',11);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (202,'2025_11_27_000001_create_inspection_material_answers_table',11);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (203,'2025_11_27_000002_create_material_bookmarks_table',11);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (204,'2025_11_25_134313_create_tenant_settings_table',12);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (205,'2025_12_01_075424_add_final_submit_columns_to_schedules_table',13);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (206,'2025_12_01_082927_add_submitted_at_to_schedules_table',14);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (207,'2025_12_01_114606_create_schedule_payouts_table',15);
INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES (208,'2025_12_01_114959_create_schedule_payout_amounts_table',15);
