-- CreateTable
CREATE TABLE `SystemLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `Employee_id` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by` DATETIME(3) NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `SystemLog_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `City` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(255) NOT NULL,
    `ar_name` VARCHAR(255) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `latitude` DECIMAL(65, 30) NULL,
    `longitude` DECIMAL(65, 30) NULL,
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `City_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Region` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(255) NOT NULL,
    `ar_name` VARCHAR(255) NULL,
    `Postal_code` VARCHAR(191) NULL,
    `latitude` DECIMAL(65, 30) NULL,
    `longitude` DECIMAL(65, 30) NULL,
    `Location` VARCHAR(191) NULL,
    `cityId` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Region_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EmployeeSectionEntryLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `sectionId` INTEGER NOT NULL,
    `employee_faclitiy_id` INTEGER NOT NULL,
    `checkIn_date` DATETIME(3) NULL,
    `checkOut_date` DATETIME(3) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `employee_FaclitiyId` INTEGER NULL,

    INDEX `EmployeeSectionEntryLog_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VisitorBranchEntryLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `branchId` INTEGER NOT NULL,
    `faclitiy_id` INTEGER NOT NULL,
    `visitor_id` INTEGER NOT NULL,
    `checkIn_date` DATETIME(3) NULL,
    `checkOut_date` DATETIME(3) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `VisitorBranchEntryLog_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Permission` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(191) NOT NULL,
    `ar_name` VARCHAR(191) NULL,
    `subject` VARCHAR(191) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Permission_deleted_en_name_idx`(`deleted`, `en_name`),
    UNIQUE INDEX `Permission_en_name_key`(`en_name`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EmployeePermission` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `start_date` DATETIME(3) NOT NULL,
    `end_date` DATETIME(3) NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `permission_id` INTEGER NOT NULL,
    `employee_id` INTEGER NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `EmployeePermission_deleted_permission_id_employee_id_idx`(`deleted`, `permission_id`, `employee_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EquipmentCategory` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `ar_name` VARCHAR(255) NULL,
    `en_name` VARCHAR(255) NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    INDEX `EquipmentCategory_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Equipment` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NULL,
    `description` VARCHAR(255) NULL,
    `Image` LONGTEXT NULL,
    `branch_id` INTEGER NOT NULL,
    `faclitiy_id` INTEGER NOT NULL,
    `category_id` INTEGER NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    INDEX `Equipment_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EquipmentLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `receipt_date` DATETIME(3) NULL DEFAULT CURRENT_TIMESTAMP(3),
    `equipment_id` INTEGER NOT NULL,
    `employee_faclitiy_id` INTEGER NOT NULL,
    `added_by_id` INTEGER NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `return_date` DATETIME(3) NULL,
    `returned` BOOLEAN NULL,
    `deleted_by_employee_id` INTEGER NULL,

    INDEX `EquipmentLog_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Visitor` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `first_name` VARCHAR(255) NOT NULL,
    `last_name` VARCHAR(255) NOT NULL,
    `slug` VARCHAR(191) NULL,
    `middle_name` VARCHAR(255) NULL,
    `email` VARCHAR(255) NOT NULL,
    `phone` VARCHAR(191) NOT NULL,
    `gender` ENUM('male', 'female') NULL,
    `nationality` VARCHAR(191) NULL,
    `residency_number` VARCHAR(191) NOT NULL,
    `ID_number` VARCHAR(191) NULL,
    `personal_photo` LONGTEXT NULL,
    `position` VARCHAR(191) NULL,
    `employer` VARCHAR(191) NULL,
    `passport_img` LONGTEXT NULL,
    `employee_id` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `blocked` BOOLEAN NOT NULL DEFAULT false,

    UNIQUE INDEX `visitor_email_unique`(`email`),
    INDEX `Visitor_deleted_slug_idx`(`deleted`, `slug`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Visit` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `visitor_id` INTEGER NOT NULL,
    `visit_reason` VARCHAR(191) NULL,
    `visit_type_id` INTEGER NULL,
    `date` DATETIME(3) NULL,
    `time` DATETIME(3) NULL,
    `visit_duration` ENUM('limited', 'unlimited') NULL DEFAULT 'unlimited',
    `Visit_frequently` BOOLEAN NOT NULL DEFAULT false,
    `end_time` DATETIME(3) NULL,
    `employee_faclitiy_id` INTEGER NULL,
    `reception_employee_id` INTEGER NULL,
    `door_id` INTEGER NULL,
    `need_NDA` BOOLEAN NULL DEFAULT false,
    `allowed_personal_items` BOOLEAN NULL,
    `personal_items` VARCHAR(191) NULL,
    `need_translator` BOOLEAN NULL DEFAULT false,
    `translator_name` VARCHAR(191) NULL,
    `visitor_type` ENUM('normal', 'VIP') NULL,
    `allowed_use_garage` BOOLEAN NULL,
    `notes` VARCHAR(191) NULL,
    `qrcode` LONGTEXT NULL,
    `visit_link` LONGTEXT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `branch_id` INTEGER NULL,
    `need_accompanying_person` BOOLEAN NOT NULL DEFAULT false,
    `accompanying_person_id` INTEGER NULL,
    `visited_employee_id` INTEGER NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `req_type` VARCHAR(191) NULL,

    INDEX `Visit_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `TokenVisit` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `visit_id` INTEGER NOT NULL,
    `token` LONGTEXT NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `TokenEmployee` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `token` LONGTEXT NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VisitSection` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `section_id` INTEGER NOT NULL,
    `visit_id` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `VisitSection_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VisitEmployee` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `visit_id` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `VisitEmployee_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VisitorSectionEntryLog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `sectionId` INTEGER NOT NULL,
    `visitorId` INTEGER NOT NULL,
    `checkIn_date` DATETIME(3) NULL,
    `checkOut_date` DATETIME(3) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `VisitorSectionEntryLog_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Section` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(255) NOT NULL,
    `ar_name` VARCHAR(255) NOT NULL,
    `branch_id` INTEGER NOT NULL,
    `desc` LONGTEXT NULL,
    `phone` VARCHAR(191) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Section_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `users` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `first_name` VARCHAR(255) NOT NULL,
    `last_name` VARCHAR(255) NOT NULL,
    `email` VARCHAR(255) NOT NULL,
    `confirmEmail` BOOLEAN NOT NULL DEFAULT false,
    `phone` VARCHAR(191) NULL,
    `person_photo` LONGTEXT NULL,
    `password` VARCHAR(255) NOT NULL,
    `address` VARCHAR(255) NOT NULL,
    `status` BOOLEAN NOT NULL DEFAULT true,
    `position` VARCHAR(191) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,

    UNIQUE INDEX `user_email_unique`(`email`),
    INDEX `users_email_idx`(`email`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Employee_Faclitiy` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `first_name` VARCHAR(255) NOT NULL,
    `last_name` VARCHAR(255) NOT NULL,
    `email` VARCHAR(255) NOT NULL,
    `confirmEmail` BOOLEAN NOT NULL DEFAULT false,
    `role` VARCHAR(191) NULL,
    `phone` VARCHAR(191) NULL,
    `person_photo` LONGTEXT NULL,
    `password` VARCHAR(255) NOT NULL,
    `address` VARCHAR(255) NOT NULL,
    `status` BOOLEAN NOT NULL DEFAULT true,
    `position` VARCHAR(191) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `is_manger` BOOLEAN NOT NULL DEFAULT false,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,
    `rqCode` LONGTEXT NULL,
    `section_id` INTEGER NULL,
    `job_title_id` INTEGER NULL,
    `company_id` INTEGER NOT NULL,
    `branch_id` INTEGER NULL,

    UNIQUE INDEX `user_email_unique`(`email`),
    INDEX `Employee_Faclitiy_email_idx`(`email`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Session` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    UNIQUE INDEX `Session_employee_id_key`(`employee_id`),
    INDEX `Session_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Session_Employee_Faclitiy` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    UNIQUE INDEX `Session_Employee_Faclitiy_employee_id_key`(`employee_id`),
    INDEX `Session_Employee_Faclitiy_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Branch` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `full_address` LONGTEXT NOT NULL,
    `latitude` DECIMAL(65, 30) NULL,
    `longitude` DECIMAL(65, 30) NULL,
    `en_name` VARCHAR(255) NULL,
    `ar_name` VARCHAR(255) NULL,
    `phone` VARCHAR(191) NULL,
    `email` VARCHAR(255) NULL,
    `work_time` VARCHAR(191) NULL,
    `facility_id` INTEGER NOT NULL,
    `regionId` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    UNIQUE INDEX `branch_email_unique`(`email`),
    INDEX `Branch_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Category` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `ar_name` VARCHAR(191) NULL,
    `en_name` VARCHAR(255) NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    UNIQUE INDEX `category_unique`(`en_name`),
    INDEX `Category_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Package` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(191) NOT NULL,
    `ar_name` VARCHAR(191) NULL,
    `en_description` MEDIUMTEXT NOT NULL,
    `ar_description` MEDIUMTEXT NULL,
    `period` INTEGER NULL,
    `infinity` BOOLEAN NOT NULL DEFAULT false,
    `total_price` DECIMAL(65, 30) NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Package_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Service` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(191) NOT NULL,
    `ar_name` VARCHAR(191) NULL,
    `en_description` MEDIUMTEXT NOT NULL,
    `ar_description` MEDIUMTEXT NULL,
    `price` DECIMAL(65, 30) NULL,
    `is_paid` BOOLEAN NOT NULL,
    `infinity` BOOLEAN NULL,
    `period` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Service_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ServicePackge` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `package_id` INTEGER NOT NULL,
    `service_id` INTEGER NOT NULL,
    `Service_table_id` INTEGER NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `ServicePackge_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ServiceTable` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `service_id` INTEGER NOT NULL,
    `price` DECIMAL(65, 30) NOT NULL,
    `limit` INTEGER NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `ServiceTable_deleted_service_id_idx`(`deleted`, `service_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `PackageSubscription` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `package_id` INTEGER NOT NULL,
    `facility_id` INTEGER NOT NULL,
    `subscription_start_date` DATETIME(3) NOT NULL,
    `subscription_end_date` DATETIME(3) NULL,
    `status` ENUM('active', 'unactive') NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `PackageSubscription_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ServiceSubscription` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `service_id` INTEGER NOT NULL,
    `facility_id` INTEGER NOT NULL,
    `Service_table_id` INTEGER NULL,
    `subscription_start_date` DATETIME(3) NOT NULL,
    `subscription_end_date` DATETIME(3) NULL,
    `status` ENUM('active', 'unactive') NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_by_employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `ServiceSubscription_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Faclitiy` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `first_name` VARCHAR(191) NULL,
    `last_name` VARCHAR(191) NULL,
    `FaclitiyType` ENUM('private', 'public') NULL,
    `category_id` INTEGER NOT NULL,
    `region_id` INTEGER NOT NULL,
    `full_address` MEDIUMTEXT NULL,
    `map_address` VARCHAR(191) NULL,
    `latitude` DECIMAL(65, 30) NULL,
    `longitude` DECIMAL(65, 30) NULL,
    `user_name` VARCHAR(191) NULL,
    `email` VARCHAR(255) NOT NULL,
    `password` VARCHAR(191) NULL,
    `phone` VARCHAR(191) NULL,
    `status` ENUM('active', 'unactive') NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,

    UNIQUE INDEX `Faclitiy_email_unique`(`email`),
    INDEX `Faclitiy_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Features` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `Extension_of_time` BOOLEAN NOT NULL DEFAULT true,
    `Enable_Late_entry` BOOLEAN NOT NULL DEFAULT true,
    `date_Late_entry` INTEGER NULL,
    `Enable_Late_checkout` BOOLEAN NOT NULL DEFAULT true,
    `date_Late_checkout` INTEGER NULL,
    `enable_Visit_reminders` BOOLEAN NOT NULL DEFAULT true,
    `type_Visit_reminders` VARCHAR(191) NULL,
    `during_Visit_reminders` INTEGER NULL,
    `enable_delayed_departure` BOOLEAN NOT NULL DEFAULT true,
    `type_delayed_departure_notification` VARCHAR(191) NULL,
    `during_delayed_departure` INTEGER NULL,
    `visits_need_accepted` BOOLEAN NOT NULL DEFAULT false,
    `faclitiy_id` INTEGER NULL,

    UNIQUE INDEX `Features_faclitiy_id_key`(`faclitiy_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CodeEnableAccount` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `code` VARCHAR(255) NOT NULL,
    `account_id` INTEGER NOT NULL,

    UNIQUE INDEX `CodeEnableAccount_account_id_key`(`account_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `randomKey` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `visit_id` INTEGER NOT NULL,
    `token` LONGTEXT NULL,

    UNIQUE INDEX `randomKey_visit_id_key`(`visit_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Notifications` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `title` VARCHAR(191) NULL,
    `desc` VARCHAR(191) NULL,
    `seen` BOOLEAN NOT NULL DEFAULT false,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    INDEX `Notifications_deleted_idx`(`deleted`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentVisitor` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `visitor_id` INTEGER NOT NULL,
    `doc_name` VARCHAR(191) NOT NULL,
    `doc_path` LONGTEXT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,
    `added_by_id` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentSection` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `section_id` INTEGER NOT NULL,
    `doc_name` VARCHAR(191) NOT NULL,
    `doc_path` LONGTEXT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,
    `added_by_id` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentSectionlog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `document_id` INTEGER NOT NULL,
    `operation` VARCHAR(191) NOT NULL,
    `employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentVisitorlog` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `document_id` INTEGER NOT NULL,
    `operation` VARCHAR(191) NOT NULL,
    `employee_id` INTEGER NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,
    `deleted_by_employee_id` INTEGER NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Managers_Visit_Request` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `employee_id` INTEGER NOT NULL,
    `branch_id` INTEGER NOT NULL,
    `section_id` INTEGER NOT NULL,
    `active` BOOLEAN NOT NULL DEFAULT true,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AcceptedVisitRequest` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `Managers_Visit_Request_id` INTEGER NOT NULL,
    `visit_req_int` INTEGER NOT NULL,
    `accepted` BOOLEAN NOT NULL DEFAULT false,
    `review` BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VisitType` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `en_name` VARCHAR(255) NOT NULL,
    `ar_name` VARCHAR(255) NOT NULL,
    `Faclitiy_id` INTEGER NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Door` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(255) NOT NULL,
    `code` VARCHAR(255) NOT NULL,
    `Faclitiy_id` INTEGER NOT NULL,
    `branch_id` INTEGER NOT NULL,
    `deleted` BOOLEAN NOT NULL DEFAULT false,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `randomKeyVisitor` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `visitor_id` INTEGER NOT NULL,
    `token` VARCHAR(191) NOT NULL,
    `added_by_id` INTEGER NOT NULL,

    UNIQUE INDEX `randomKeyVisitor_visitor_id_key`(`visitor_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `JobTitle` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `title` VARCHAR(191) NULL,
    `Faclitiy_id` INTEGER NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `SystemLog` ADD CONSTRAINT `SystemLog_Employee_id_fkey` FOREIGN KEY (`Employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `City` ADD CONSTRAINT `City_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Region` ADD CONSTRAINT `Region_cityId_fkey` FOREIGN KEY (`cityId`) REFERENCES `City`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeeSectionEntryLog` ADD CONSTRAINT `EmployeeSectionEntryLog_sectionId_fkey` FOREIGN KEY (`sectionId`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeeSectionEntryLog` ADD CONSTRAINT `EmployeeSectionEntryLog_employee_faclitiy_id_fkey` FOREIGN KEY (`employee_faclitiy_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeeSectionEntryLog` ADD CONSTRAINT `EmployeeSectionEntryLog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorBranchEntryLog` ADD CONSTRAINT `VisitorBranchEntryLog_branchId_fkey` FOREIGN KEY (`branchId`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorBranchEntryLog` ADD CONSTRAINT `VisitorBranchEntryLog_faclitiy_id_fkey` FOREIGN KEY (`faclitiy_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorBranchEntryLog` ADD CONSTRAINT `VisitorBranchEntryLog_visitor_id_fkey` FOREIGN KEY (`visitor_id`) REFERENCES `Visitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorBranchEntryLog` ADD CONSTRAINT `VisitorBranchEntryLog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Permission` ADD CONSTRAINT `Permission_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeePermission` ADD CONSTRAINT `EmployeePermission_permission_id_fkey` FOREIGN KEY (`permission_id`) REFERENCES `Permission`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeePermission` ADD CONSTRAINT `EmployeePermission_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EmployeePermission` ADD CONSTRAINT `EmployeePermission_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EquipmentCategory` ADD CONSTRAINT `EquipmentCategory_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Equipment` ADD CONSTRAINT `Equipment_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Equipment` ADD CONSTRAINT `Equipment_faclitiy_id_fkey` FOREIGN KEY (`faclitiy_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Equipment` ADD CONSTRAINT `Equipment_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `EquipmentCategory`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Equipment` ADD CONSTRAINT `Equipment_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EquipmentLog` ADD CONSTRAINT `EquipmentLog_equipment_id_fkey` FOREIGN KEY (`equipment_id`) REFERENCES `Equipment`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EquipmentLog` ADD CONSTRAINT `EquipmentLog_employee_faclitiy_id_fkey` FOREIGN KEY (`employee_faclitiy_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EquipmentLog` ADD CONSTRAINT `EquipmentLog_added_by_id_fkey` FOREIGN KEY (`added_by_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EquipmentLog` ADD CONSTRAINT `EquipmentLog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visitor` ADD CONSTRAINT `Visitor_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visitor` ADD CONSTRAINT `Visitor_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_visitor_id_fkey` FOREIGN KEY (`visitor_id`) REFERENCES `Visitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_visit_type_id_fkey` FOREIGN KEY (`visit_type_id`) REFERENCES `VisitType`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_employee_faclitiy_id_fkey` FOREIGN KEY (`employee_faclitiy_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_reception_employee_id_fkey` FOREIGN KEY (`reception_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_door_id_fkey` FOREIGN KEY (`door_id`) REFERENCES `Door`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_accompanying_person_id_fkey` FOREIGN KEY (`accompanying_person_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_visited_employee_id_fkey` FOREIGN KEY (`visited_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Visit` ADD CONSTRAINT `Visit_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TokenVisit` ADD CONSTRAINT `TokenVisit_visit_id_fkey` FOREIGN KEY (`visit_id`) REFERENCES `Visit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `TokenEmployee` ADD CONSTRAINT `TokenEmployee_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitSection` ADD CONSTRAINT `VisitSection_section_id_fkey` FOREIGN KEY (`section_id`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitSection` ADD CONSTRAINT `VisitSection_visit_id_fkey` FOREIGN KEY (`visit_id`) REFERENCES `Visit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitSection` ADD CONSTRAINT `VisitSection_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitEmployee` ADD CONSTRAINT `VisitEmployee_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitEmployee` ADD CONSTRAINT `VisitEmployee_visit_id_fkey` FOREIGN KEY (`visit_id`) REFERENCES `Visit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitEmployee` ADD CONSTRAINT `VisitEmployee_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorSectionEntryLog` ADD CONSTRAINT `VisitorSectionEntryLog_sectionId_fkey` FOREIGN KEY (`sectionId`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorSectionEntryLog` ADD CONSTRAINT `VisitorSectionEntryLog_visitorId_fkey` FOREIGN KEY (`visitorId`) REFERENCES `Visitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitorSectionEntryLog` ADD CONSTRAINT `VisitorSectionEntryLog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Section` ADD CONSTRAINT `Section_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `users` ADD CONSTRAINT `users_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Employee_Faclitiy` ADD CONSTRAINT `Employee_Faclitiy_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Employee_Faclitiy` ADD CONSTRAINT `Employee_Faclitiy_section_id_fkey` FOREIGN KEY (`section_id`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Employee_Faclitiy` ADD CONSTRAINT `Employee_Faclitiy_job_title_id_fkey` FOREIGN KEY (`job_title_id`) REFERENCES `JobTitle`(`id`) ON DELETE NO ACTION ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Employee_Faclitiy` ADD CONSTRAINT `Employee_Faclitiy_company_id_fkey` FOREIGN KEY (`company_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Employee_Faclitiy` ADD CONSTRAINT `Employee_Faclitiy_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Session` ADD CONSTRAINT `Session_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Session_Employee_Faclitiy` ADD CONSTRAINT `Session_Employee_Faclitiy_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Branch` ADD CONSTRAINT `Branch_facility_id_fkey` FOREIGN KEY (`facility_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Branch` ADD CONSTRAINT `Branch_regionId_fkey` FOREIGN KEY (`regionId`) REFERENCES `Region`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Branch` ADD CONSTRAINT `Branch_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Category` ADD CONSTRAINT `Category_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Package` ADD CONSTRAINT `Package_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Service` ADD CONSTRAINT `Service_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServicePackge` ADD CONSTRAINT `ServicePackge_package_id_fkey` FOREIGN KEY (`package_id`) REFERENCES `Package`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServicePackge` ADD CONSTRAINT `ServicePackge_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `Service`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServicePackge` ADD CONSTRAINT `ServicePackge_Service_table_id_fkey` FOREIGN KEY (`Service_table_id`) REFERENCES `ServiceTable`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServicePackge` ADD CONSTRAINT `ServicePackge_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceTable` ADD CONSTRAINT `ServiceTable_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `Service`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PackageSubscription` ADD CONSTRAINT `PackageSubscription_package_id_fkey` FOREIGN KEY (`package_id`) REFERENCES `Package`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PackageSubscription` ADD CONSTRAINT `PackageSubscription_facility_id_fkey` FOREIGN KEY (`facility_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `PackageSubscription` ADD CONSTRAINT `PackageSubscription_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceSubscription` ADD CONSTRAINT `ServiceSubscription_service_id_fkey` FOREIGN KEY (`service_id`) REFERENCES `Service`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceSubscription` ADD CONSTRAINT `ServiceSubscription_facility_id_fkey` FOREIGN KEY (`facility_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceSubscription` ADD CONSTRAINT `ServiceSubscription_Service_table_id_fkey` FOREIGN KEY (`Service_table_id`) REFERENCES `ServiceTable`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceSubscription` ADD CONSTRAINT `ServiceSubscription_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Faclitiy` ADD CONSTRAINT `Faclitiy_category_id_fkey` FOREIGN KEY (`category_id`) REFERENCES `Category`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Faclitiy` ADD CONSTRAINT `Faclitiy_region_id_fkey` FOREIGN KEY (`region_id`) REFERENCES `Region`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Faclitiy` ADD CONSTRAINT `Faclitiy_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Features` ADD CONSTRAINT `Features_faclitiy_id_fkey` FOREIGN KEY (`faclitiy_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CodeEnableAccount` ADD CONSTRAINT `CodeEnableAccount_account_id_fkey` FOREIGN KEY (`account_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `randomKey` ADD CONSTRAINT `randomKey_visit_id_fkey` FOREIGN KEY (`visit_id`) REFERENCES `Visit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Notifications` ADD CONSTRAINT `Notifications_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitor` ADD CONSTRAINT `DocumentVisitor_visitor_id_fkey` FOREIGN KEY (`visitor_id`) REFERENCES `Visitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitor` ADD CONSTRAINT `DocumentVisitor_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitor` ADD CONSTRAINT `DocumentVisitor_added_by_id_fkey` FOREIGN KEY (`added_by_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSection` ADD CONSTRAINT `DocumentSection_section_id_fkey` FOREIGN KEY (`section_id`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSection` ADD CONSTRAINT `DocumentSection_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSection` ADD CONSTRAINT `DocumentSection_added_by_id_fkey` FOREIGN KEY (`added_by_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSectionlog` ADD CONSTRAINT `DocumentSectionlog_document_id_fkey` FOREIGN KEY (`document_id`) REFERENCES `DocumentSection`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSectionlog` ADD CONSTRAINT `DocumentSectionlog_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentSectionlog` ADD CONSTRAINT `DocumentSectionlog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitorlog` ADD CONSTRAINT `DocumentVisitorlog_document_id_fkey` FOREIGN KEY (`document_id`) REFERENCES `DocumentVisitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitorlog` ADD CONSTRAINT `DocumentVisitorlog_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentVisitorlog` ADD CONSTRAINT `DocumentVisitorlog_deleted_by_employee_id_fkey` FOREIGN KEY (`deleted_by_employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Managers_Visit_Request` ADD CONSTRAINT `Managers_Visit_Request_employee_id_fkey` FOREIGN KEY (`employee_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Managers_Visit_Request` ADD CONSTRAINT `Managers_Visit_Request_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Managers_Visit_Request` ADD CONSTRAINT `Managers_Visit_Request_section_id_fkey` FOREIGN KEY (`section_id`) REFERENCES `Section`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AcceptedVisitRequest` ADD CONSTRAINT `AcceptedVisitRequest_Managers_Visit_Request_id_fkey` FOREIGN KEY (`Managers_Visit_Request_id`) REFERENCES `Managers_Visit_Request`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AcceptedVisitRequest` ADD CONSTRAINT `AcceptedVisitRequest_visit_req_int_fkey` FOREIGN KEY (`visit_req_int`) REFERENCES `Visit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VisitType` ADD CONSTRAINT `VisitType_Faclitiy_id_fkey` FOREIGN KEY (`Faclitiy_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Door` ADD CONSTRAINT `Door_Faclitiy_id_fkey` FOREIGN KEY (`Faclitiy_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Door` ADD CONSTRAINT `Door_branch_id_fkey` FOREIGN KEY (`branch_id`) REFERENCES `Branch`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `randomKeyVisitor` ADD CONSTRAINT `randomKeyVisitor_visitor_id_fkey` FOREIGN KEY (`visitor_id`) REFERENCES `Visitor`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `randomKeyVisitor` ADD CONSTRAINT `randomKeyVisitor_added_by_id_fkey` FOREIGN KEY (`added_by_id`) REFERENCES `Employee_Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `JobTitle` ADD CONSTRAINT `JobTitle_Faclitiy_id_fkey` FOREIGN KEY (`Faclitiy_id`) REFERENCES `Faclitiy`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
