-- CreateTable
CREATE TABLE `User` (
    `id` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `passwordHash` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `phone` VARCHAR(191) NULL,
    `role` ENUM('SUPER_ADMIN', 'USER', 'EXECUTOR', 'BENEFICIARY', 'PROFESSIONAL', 'SHARIAH_BOARD') NOT NULL DEFAULT 'USER',
    `mfaEnabled` BOOLEAN NOT NULL DEFAULT false,
    `mfaSecret` VARCHAR(191) NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `emailVerified` BOOLEAN NOT NULL DEFAULT false,
    `ssoProvider` VARCHAR(191) NULL,
    `lastLogin` DATETIME(3) NULL,
    `state` ENUM('KA', 'KL', 'TN', 'TS', 'AP', 'DL', 'HR', 'HP', 'JK', 'PB', 'RJ', 'UK', 'UP', 'GA', 'GJ', 'MH', 'CT', 'MP', 'BR', 'JH', 'OD', 'WB', 'AR', 'AS', 'ML', 'MN', 'MZ', 'NL', 'SK', 'TR', 'AN', 'CH', 'DD', 'LA', 'LD', 'PY') NULL,
    `doctrine` ENUM('SUNNI_HANAFI', 'SUNNI_SHAFII', 'SUNNI_MALIKI', 'SUNNI_HANBALI', 'SHIA_JAFARI') NULL,
    `deletedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `Session` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `token` VARCHAR(191) NOT NULL,
    `deviceInfo` VARCHAR(191) NULL,
    `ipAddress` VARCHAR(191) NULL,
    `expiresAt` DATETIME(3) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `Session_token_key`(`token`),
    INDEX `Session_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `FamilyMember` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `gender` ENUM('MALE', 'FEMALE') NOT NULL,
    `relationship` ENUM('SPOUSE', 'CHILD', 'PARENT', 'SIBLING', 'GRANDPARENT', 'GRANDCHILD', 'UNCLE', 'AUNT') NOT NULL,
    `siblingSubtype` ENUM('FULL', 'HALF_PATERNAL', 'HALF_MATERNAL', 'STEP') NULL,
    `status` ENUM('ALIVE', 'DECEASED') NOT NULL DEFAULT 'ALIVE',
    `dateOfBirth` DATETIME(3) NULL,
    `dateOfDeath` DATETIME(3) NULL,
    `isMinor` BOOLEAN NOT NULL DEFAULT false,
    `dependencyNotes` TEXT NULL,
    `contactEmail` VARCHAR(191) NULL,
    `contactPhone` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,
    `parentId` VARCHAR(191) NULL,
    `spouseId` VARCHAR(191) NULL,

    UNIQUE INDEX `FamilyMember_spouseId_key`(`spouseId`),
    INDEX `FamilyMember_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Asset` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `category` ENUM('IMMOVABLE_PROPERTY', 'BANK_ACCOUNT', 'FIXED_DEPOSIT', 'MUTUAL_FUND', 'STOCKS', 'GOLD_JEWELRY', 'VEHICLE', 'BUSINESS_INTEREST', 'DIGITAL_ASSET', 'INSURANCE', 'EPF_PPF', 'INTELLECTUAL_PROPERTY', 'OTHER') NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `location` VARCHAR(191) NULL,
    `surveyNumber` VARCHAR(191) NULL,
    `ownershipPercent` DOUBLE NOT NULL DEFAULT 100,
    `currentValue` DOUBLE NOT NULL,
    `nomineeInfo` VARCHAR(191) NULL,
    `jointHolderInfo` VARCHAR(191) NULL,
    `documentUrls` JSON NOT NULL,
    `notes` TEXT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Asset_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Liability` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `category` ENUM('HOME_LOAN', 'VEHICLE_LOAN', 'PERSONAL_LOAN', 'CREDIT_CARD', 'BUSINESS_LOAN', 'GOLD_LOAN', 'ZAKAT_ARREARS', 'CHARITY_COMMITMENT', 'TAX_OBLIGATION', 'INFORMAL_DEBT', 'OTHER') NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `lender` VARCHAR(191) NULL,
    `outstandingAmount` DOUBLE NOT NULL,
    `interestRate` DOUBLE NULL,
    `emiAmount` DOUBLE NULL,
    `maturityDate` DATETIME(3) NULL,
    `collateral` VARCHAR(191) NULL,
    `notes` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Liability_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Bequest` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `beneficiaryId` VARCHAR(191) NULL,
    `type` ENUM('SPECIFIC_AMOUNT', 'PERCENTAGE_OF_ESTATE', 'SPECIFIC_ASSET', 'CHARITY_DONATION', 'SADAQAH_JARIYAH') NOT NULL,
    `beneficiaryName` VARCHAR(191) NOT NULL,
    `beneficiaryContact` VARCHAR(191) NULL,
    `amount` DOUBLE NULL,
    `percentage` DOUBLE NULL,
    `assetId` VARCHAR(191) NULL,
    `purpose` VARCHAR(191) NULL,
    `conditions` VARCHAR(191) NULL,
    `charityName` VARCHAR(191) NULL,
    `charityRegistration` VARCHAR(191) NULL,
    `isValidated` BOOLEAN NOT NULL DEFAULT false,
    `validationErrors` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Bequest_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `InheritanceCalculation` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `doctrine` ENUM('SUNNI_HANAFI', 'SUNNI_SHAFII', 'SUNNI_MALIKI', 'SUNNI_HANBALI', 'SHIA_JAFARI') NOT NULL,
    `rulebookVersion` VARCHAR(191) NOT NULL,
    `status` ENUM('DRAFT', 'PROVISIONAL', 'FINAL') NOT NULL DEFAULT 'DRAFT',
    `familySnapshot` JSON NOT NULL,
    `assetSummary` JSON NULL,
    `netEstate` DOUBLE NULL,
    `bequestTotal` DOUBLE NULL,
    `distributableEstate` DOUBLE NULL,
    `adjustmentType` ENUM('NONE', 'AWL', 'RADD') NOT NULL DEFAULT 'NONE',
    `adjustmentDetails` JSON NULL,
    `calculationTrace` JSON NOT NULL,
    `validations` JSON NOT NULL,
    `certificateHash` VARCHAR(191) NULL,
    `tdbNodes` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `InheritanceCalculation_userId_idx`(`userId`),
    INDEX `InheritanceCalculation_certificateHash_idx`(`certificateHash`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `CalculationShare` (
    `id` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NOT NULL,
    `familyMemberId` VARCHAR(191) NOT NULL,
    `heirName` VARCHAR(191) NOT NULL,
    `relationship` ENUM('SPOUSE', 'CHILD', 'PARENT', 'SIBLING', 'GRANDPARENT', 'GRANDCHILD', 'UNCLE', 'AUNT') NOT NULL,
    `fraction` VARCHAR(191) NOT NULL,
    `decimal` DOUBLE NOT NULL,
    `percentage` DOUBLE NOT NULL,
    `isFixed` BOOLEAN NOT NULL,
    `ruleIds` JSON NOT NULL,
    `citations` JSON NOT NULL,
    `explanation` TEXT NOT NULL,
    `wasAdjusted` BOOLEAN NOT NULL DEFAULT false,
    `originalFraction` VARCHAR(191) NULL,
    `originalDecimal` DOUBLE NULL,

    INDEX `CalculationShare_calculationId_idx`(`calculationId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentPack` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NOT NULL,
    `status` ENUM('DRAFT', 'PREVIEW', 'FINAL') NOT NULL DEFAULT 'DRAFT',
    `packHash` VARCHAR(191) NULL,
    `verificationUrl` VARCHAR(191) NULL,
    `state` ENUM('KA', 'KL', 'TN', 'TS', 'AP', 'DL', 'HR', 'HP', 'JK', 'PB', 'RJ', 'UK', 'UP', 'GA', 'GJ', 'MH', 'CT', 'MP', 'BR', 'JH', 'OD', 'WB', 'AR', 'AS', 'ML', 'MN', 'MZ', 'NL', 'SK', 'TR', 'AN', 'CH', 'DD', 'LA', 'LD', 'PY') NOT NULL,
    `documents` JSON NOT NULL,
    `generatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `creditConsumed` BOOLEAN NOT NULL DEFAULT false,

    INDEX `DocumentPack_userId_idx`(`userId`),
    INDEX `DocumentPack_packHash_idx`(`packHash`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VaultItem` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `category` VARCHAR(191) NOT NULL,
    `encryptedData` TEXT NOT NULL,
    `iv` VARCHAR(191) NOT NULL,
    `authTag` VARCHAR(191) NOT NULL,
    `metadata` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `VaultItem_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `EmergencyAccess` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `method` ENUM('TIME_LOCK_INACTIVITY', 'TRUSTED_QUORUM', 'MANUAL_RELEASE', 'PREMIUM_ASSISTED') NOT NULL,
    `inactivityDays` INTEGER NULL,
    `countdownDays` INTEGER NULL,
    `trustedPersons` JSON NULL,
    `quorumRequired` INTEGER NULL,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `lastActivityAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `EdgeCase` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NULL,
    `ruleNodeId` VARCHAR(191) NOT NULL,
    `doctrine` ENUM('SUNNI_HANAFI', 'SUNNI_SHAFII', 'SUNNI_MALIKI', 'SUNNI_HANBALI', 'SHIA_JAFARI') NOT NULL,
    `familyContext` JSON NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `status` ENUM('SUBMITTED', 'ASSIGNED', 'UNDER_REVIEW', 'RESOLVED', 'ESCALATED') NOT NULL DEFAULT 'SUBMITTED',
    `assignedTo` VARCHAR(191) NULL,
    `resolution` VARCHAR(191) NULL,
    `resolutionRule` JSON NULL,
    `submittedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `resolvedAt` DATETIME(3) NULL,

    INDEX `EdgeCase_status_idx`(`status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Professional` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `type` ENUM('SHARIAH_SCHOLAR', 'ESTATE_LAWYER', 'TAX_ADVISOR', 'MEDIATOR', 'ADVOCATE', 'DOCUMENT_REGISTRATION', 'COURT_FILING', 'PROPERTY_MUTATION', 'STAMP_DUTY', 'ADVISORY_CONSULTATION') NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `credentials` VARCHAR(191) NOT NULL,
    `institution` VARCHAR(191) NULL,
    `specializations` JSON NOT NULL,
    `states` JSON NOT NULL,
    `bio` TEXT NULL,
    `rating` DOUBLE NOT NULL DEFAULT 0,
    `reviewCount` INTEGER NOT NULL DEFAULT 0,
    `isVerified` BOOLEAN NOT NULL DEFAULT false,
    `isActive` BOOLEAN NOT NULL DEFAULT true,
    `hourlyRate` DOUBLE NULL,
    `contactEmail` VARCHAR(191) NULL,
    `contactPhone` VARCHAR(191) NULL,
    `servicesOffered` JSON NOT NULL,
    `registrationStatus` VARCHAR(191) NOT NULL DEFAULT 'PENDING',
    `rejectionReason` VARCHAR(191) NULL,
    `approvedAt` DATETIME(3) NULL,
    `approvedBy` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

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

-- CreateTable
CREATE TABLE `ProfessionalReview` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `professionalId` VARCHAR(191) NOT NULL,
    `type` VARCHAR(191) NOT NULL,
    `status` ENUM('REQUESTED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED') NOT NULL DEFAULT 'REQUESTED',
    `calculationId` VARCHAR(191) NULL,
    `reviewNotes` VARCHAR(191) NULL,
    `reviewDocument` VARCHAR(191) NULL,
    `amount` DOUBLE NOT NULL,
    `paidAt` DATETIME(3) NULL,
    `completedAt` DATETIME(3) NULL,
    `rating` INTEGER NULL,
    `feedback` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `ProfessionalReview_userId_idx`(`userId`),
    INDEX `ProfessionalReview_professionalId_idx`(`professionalId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ServiceRequest` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `professionalId` VARCHAR(191) NOT NULL,
    `serviceType` ENUM('SHARIAH_SCHOLAR', 'ESTATE_LAWYER', 'TAX_ADVISOR', 'MEDIATOR', 'ADVOCATE', 'DOCUMENT_REGISTRATION', 'COURT_FILING', 'PROPERTY_MUTATION', 'STAMP_DUTY', 'ADVISORY_CONSULTATION') NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `documents` JSON NULL,
    `amount` DOUBLE NOT NULL,
    `status` ENUM('PENDING', 'ACCEPTED', 'REJECTED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED', 'DISPUTED') NOT NULL DEFAULT 'PENDING',
    `razorpayOrderId` VARCHAR(191) NULL,
    `razorpayPaymentId` VARCHAR(191) NULL,
    `paidAt` DATETIME(3) NULL,
    `acceptedAt` DATETIME(3) NULL,
    `rejectedAt` DATETIME(3) NULL,
    `rejectionReason` VARCHAR(191) NULL,
    `completedAt` DATETIME(3) NULL,
    `cancelledAt` DATETIME(3) NULL,
    `rating` INTEGER NULL,
    `feedback` VARCHAR(191) NULL,
    `notes` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `ServiceRequest_userId_idx`(`userId`),
    INDEX `ServiceRequest_professionalId_idx`(`professionalId`),
    INDEX `ServiceRequest_status_idx`(`status`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Subscription` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `plan` ENUM('ESSENTIAL', 'VAULT', 'VAULT_FAMILY', 'PROFESSIONAL', 'ENTERPRISE') NOT NULL,
    `status` ENUM('ACTIVE', 'EXPIRED', 'CANCELLED', 'TRIAL') NOT NULL DEFAULT 'TRIAL',
    `startDate` DATETIME(3) NOT NULL,
    `endDate` DATETIME(3) NOT NULL,
    `creditsTotal` INTEGER NOT NULL,
    `creditsUsed` INTEGER NOT NULL DEFAULT 0,
    `seatsTotal` INTEGER NOT NULL,
    `seatsUsed` INTEGER NOT NULL DEFAULT 0,
    `razorpaySubId` VARCHAR(191) NULL,
    `razorpayPlanId` VARCHAR(191) NULL,
    `amount` DOUBLE NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `Subscription_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `LifeEvent` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `type` ENUM('NEW_CHILD', 'MARRIAGE', 'DIVORCE', 'PARENT_DEATH', 'SPOUSE_DEATH', 'CHILD_DEATH', 'ASSET_ACQUIRED', 'ASSET_SOLD', 'DEBT_TAKEN', 'DEBT_SETTLED', 'MOVED_STATE', 'RETIREMENT') NOT NULL,
    `description` VARCHAR(191) NOT NULL,
    `date` DATETIME(3) NOT NULL,
    `impactSummary` VARCHAR(191) NULL,
    `reviewRequired` BOOLEAN NOT NULL DEFAULT true,
    `reviewedAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `LifeEvent_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `AuditLog` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NULL,
    `action` VARCHAR(191) NOT NULL,
    `entityType` VARCHAR(191) NOT NULL,
    `entityId` VARCHAR(191) NULL,
    `beforeState` JSON NULL,
    `afterState` JSON NULL,
    `ipAddress` VARCHAR(191) NULL,
    `previousHash` VARCHAR(191) NULL,
    `hash` VARCHAR(191) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `AuditLog_userId_idx`(`userId`),
    INDEX `AuditLog_entityType_entityId_idx`(`entityType`, `entityId`),
    INDEX `AuditLog_createdAt_idx`(`createdAt`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `OrisInteraction` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `queryType` VARCHAR(191) NOT NULL,
    `query` TEXT NOT NULL,
    `response` TEXT NOT NULL,
    `context` JSON NULL,
    `confidence` DOUBLE NULL,
    `tokensUsed` INTEGER NULL,
    `latencyMs` INTEGER NULL,
    `costUsd` DOUBLE NULL,
    `feedback` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `OrisInteraction_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ConsentLog` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `purpose` ENUM('ESTATE_PLANNING', 'DOCUMENT_STORAGE', 'ORIS_AI_PROCESSING', 'PROFESSIONAL_REFERRAL', 'MARKETING', 'ANALYTICS') NOT NULL,
    `grantedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `revokedAt` DATETIME(3) NULL,
    `noticeVersion` VARCHAR(191) NOT NULL,
    `channel` VARCHAR(191) NOT NULL DEFAULT 'web',

    INDEX `ConsentLog_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ZakatCalculation` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `doctrine` ENUM('SUNNI_HANAFI', 'SUNNI_SHAFII', 'SUNNI_MALIKI', 'SUNNI_HANBALI', 'SHIA_JAFARI') NOT NULL,
    `label` VARCHAR(191) NULL,
    `encryptedData` TEXT NOT NULL,
    `iv` VARCHAR(191) NOT NULL,
    `authTag` VARCHAR(191) NOT NULL,
    `nisabMet` BOOLEAN NOT NULL,
    `zakatDue` DOUBLE NOT NULL,
    `zakatYear` INTEGER NOT NULL,
    `certificateHash` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `ZakatCalculation_userId_idx`(`userId`),
    INDEX `ZakatCalculation_userId_zakatYear_idx`(`userId`, `zakatYear`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ZakatNGO` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `registrationNumber` VARCHAR(191) NULL,
    `fcraNumber` VARCHAR(191) NULL,
    `section80GNumber` VARCHAR(191) NULL,
    `description` TEXT NOT NULL,
    `mission` TEXT NULL,
    `website` VARCHAR(191) NULL,
    `contactEmail` VARCHAR(191) NOT NULL,
    `contactPhone` VARCHAR(191) NULL,
    `address` TEXT NOT NULL,
    `state` ENUM('KA', 'KL', 'TN', 'TS', 'AP', 'DL', 'HR', 'HP', 'JK', 'PB', 'RJ', 'UK', 'UP', 'GA', 'GJ', 'MH', 'CT', 'MP', 'BR', 'JH', 'OD', 'WB', 'AR', 'AS', 'ML', 'MN', 'MZ', 'NL', 'SK', 'TR', 'AN', 'CH', 'DD', 'LA', 'LD', 'PY') NOT NULL,
    `city` VARCHAR(191) NULL,
    `asnaafCategories` JSON NOT NULL,
    `status` ENUM('PENDING', 'APPROVED', 'REJECTED', 'SUSPENDED') NOT NULL DEFAULT 'PENDING',
    `isVerified` BOOLEAN NOT NULL DEFAULT false,
    `donateazyListed` BOOLEAN NOT NULL DEFAULT false,
    `donateazyId` VARCHAR(191) NULL,
    `logoUrl` VARCHAR(191) NULL,
    `socialLinks` JSON NULL,
    `rejectionReason` VARCHAR(191) NULL,
    `approvedAt` DATETIME(3) NULL,
    `approvedBy` VARCHAR(191) NULL,
    `submittedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    INDEX `ZakatNGO_status_idx`(`status`),
    INDEX `ZakatNGO_state_idx`(`state`),
    INDEX `ZakatNGO_donateazyListed_idx`(`donateazyListed`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `DocumentIdentifier` (
    `id` VARCHAR(191) NOT NULL,
    `din` VARCHAR(191) NOT NULL,
    `year` INTEGER NOT NULL,
    `stateCode` VARCHAR(191) NOT NULL,
    `sequence` INTEGER NOT NULL,
    `documentPackId` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'ACTIVE',
    `issuedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `revokedAt` DATETIME(3) NULL,
    `revokedReason` VARCHAR(191) NULL,

    UNIQUE INDEX `DocumentIdentifier_din_key`(`din`),
    UNIQUE INDEX `DocumentIdentifier_documentPackId_key`(`documentPackId`),
    UNIQUE INDEX `DocumentIdentifier_calculationId_key`(`calculationId`),
    INDEX `DocumentIdentifier_userId_idx`(`userId`),
    INDEX `DocumentIdentifier_calculationId_idx`(`calculationId`),
    UNIQUE INDEX `DocumentIdentifier_year_stateCode_sequence_key`(`year`, `stateCode`, `sequence`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Witness` (
    `id` VARCHAR(191) NOT NULL,
    `documentPackId` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `name` VARCHAR(191) NOT NULL,
    `email` VARCHAR(191) NOT NULL,
    `phone` VARCHAR(191) NULL,
    `relationship` VARCHAR(191) NULL,
    `aadhaarLast4` VARCHAR(191) NULL,
    `token` VARCHAR(191) NOT NULL,
    `tokenExpiresAt` DATETIME(3) NOT NULL,
    `status` ENUM('INVITED', 'ACCEPTED', 'ATTESTED', 'DECLINED', 'EXPIRED') NOT NULL DEFAULT 'INVITED',
    `invitedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `attestedAt` DATETIME(3) NULL,
    `declinedAt` DATETIME(3) NULL,

    UNIQUE INDEX `Witness_token_key`(`token`),
    INDEX `Witness_documentPackId_idx`(`documentPackId`),
    INDEX `Witness_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `WitnessAttestation` (
    `id` VARCHAR(191) NOT NULL,
    `witnessId` VARCHAR(191) NOT NULL,
    `documentPackId` VARCHAR(191) NOT NULL,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` VARCHAR(191) NULL,
    `attestedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `declaration` TEXT NOT NULL,

    INDEX `WitnessAttestation_witnessId_idx`(`witnessId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `Signature` (
    `id` VARCHAR(191) NOT NULL,
    `documentPackId` VARCHAR(191) NOT NULL,
    `signerId` VARCHAR(191) NOT NULL,
    `signerType` ENUM('TESTATOR', 'EXECUTOR', 'WITNESS', 'NOTARY') NOT NULL,
    `signerName` VARCHAR(191) NOT NULL,
    `signatureData` TEXT NOT NULL,
    `signatureHash` VARCHAR(191) NOT NULL,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` VARCHAR(191) NULL,
    `signedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `witnessId` VARCHAR(191) NULL,
    `executorId` VARCHAR(191) NULL,
    `signingSessionId` VARCHAR(191) NULL,

    INDEX `Signature_documentPackId_idx`(`documentPackId`),
    INDEX `Signature_signerId_idx`(`signerId`),
    INDEX `Signature_signingSessionId_idx`(`signingSessionId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `ExecutorAppointment` (
    `id` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NOT NULL,
    `executorUserId` VARCHAR(191) NULL,
    `executorName` VARCHAR(191) NOT NULL,
    `executorEmail` VARCHAR(191) NOT NULL,
    `executorPhone` VARCHAR(191) NULL,
    `token` VARCHAR(191) NOT NULL,
    `tokenExpiresAt` DATETIME(3) NOT NULL,
    `status` ENUM('INVITED', 'ACCEPTED', 'ACTIVE', 'DECLINED', 'REVOKED', 'COMPLETED') NOT NULL DEFAULT 'INVITED',
    `isPrimary` BOOLEAN NOT NULL DEFAULT false,
    `appointedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `acceptedAt` DATETIME(3) NULL,
    `declinedAt` DATETIME(3) NULL,

    UNIQUE INDEX `ExecutorAppointment_token_key`(`token`),
    INDEX `ExecutorAppointment_calculationId_idx`(`calculationId`),
    INDEX `ExecutorAppointment_executorUserId_idx`(`executorUserId`),
    INDEX `ExecutorAppointment_executorEmail_idx`(`executorEmail`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `IdentityVerification` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `verificationType` ENUM('SELF_DECLARATION', 'AADHAAR_BASIC', 'AADHAAR_DIGILOCKER', 'MANUAL_UPLOAD') NOT NULL,
    `fullName` VARCHAR(191) NOT NULL,
    `dateOfBirth` DATETIME(3) NULL,
    `aadhaarLast4` VARCHAR(191) NULL,
    `aadhaarVerified` BOOLEAN NOT NULL DEFAULT false,
    `addressLine1` VARCHAR(191) NULL,
    `addressCity` VARCHAR(191) NULL,
    `addressState` VARCHAR(191) NULL,
    `addressPincode` VARCHAR(191) NULL,
    `documentUrl` VARCHAR(191) NULL,
    `verifiedAt` DATETIME(3) NULL,
    `expiresAt` DATETIME(3) NULL,
    `status` VARCHAR(191) NOT NULL DEFAULT 'PENDING',
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `IdentityVerification_userId_idx`(`userId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `SigningSession` (
    `id` VARCHAR(191) NOT NULL,
    `documentPackId` VARCHAR(191) NOT NULL,
    `signerType` ENUM('TESTATOR', 'EXECUTOR', 'WITNESS', 'NOTARY') NOT NULL,
    `signerIdentifier` VARCHAR(191) NOT NULL,
    `signerName` VARCHAR(191) NOT NULL,
    `signerEmail` VARCHAR(191) NOT NULL,
    `verificationMethod` ENUM('EMAIL_OTP', 'SMS_OTP', 'LOGGED_IN_SESSION', 'TOKEN_AUTH') NOT NULL,
    `otpHash` VARCHAR(191) NULL,
    `otpExpiresAt` DATETIME(3) NULL,
    `otpAttempts` INTEGER NOT NULL DEFAULT 0,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` VARCHAR(191) NULL,
    `deviceFingerprint` JSON NULL,
    `status` ENUM('CREATED', 'OTP_SENT', 'OTP_VERIFIED', 'DOCUMENT_VIEWED', 'SIGNATURE_DRAWN', 'COMPLETED', 'EXPIRED', 'FAILED') NOT NULL DEFAULT 'CREATED',
    `expiresAt` DATETIME(3) NOT NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `completedAt` DATETIME(3) NULL,

    INDEX `SigningSession_documentPackId_idx`(`documentPackId`),
    INDEX `SigningSession_signerIdentifier_idx`(`signerIdentifier`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `SigningEvent` (
    `id` VARCHAR(191) NOT NULL,
    `signingSessionId` VARCHAR(191) NOT NULL,
    `eventType` ENUM('SESSION_CREATED', 'OTP_SENT', 'OTP_VERIFIED', 'OTP_FAILED', 'DOCUMENT_VIEWED', 'SIGNATURE_DRAWN', 'SIGNATURE_CONFIRMED', 'SIGNATURE_EMBEDDED', 'SESSION_EXPIRED') NOT NULL,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` VARCHAR(191) NULL,
    `metadata` JSON NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    INDEX `SigningEvent_signingSessionId_idx`(`signingSessionId`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VideoMessage` (
    `id` VARCHAR(191) NOT NULL,
    `userId` VARCHAR(191) NOT NULL,
    `title` VARCHAR(191) NOT NULL,
    `description` VARCHAR(191) NULL,
    `recipientName` VARCHAR(191) NOT NULL,
    `recipientEmail` VARCHAR(191) NOT NULL,
    `recipientPhone` VARCHAR(191) NULL,
    `relationship` VARCHAR(191) NULL,
    `s3Key` VARCHAR(191) NULL,
    `duration` INTEGER NULL,
    `fileSize` INTEGER NULL,
    `mimeType` VARCHAR(191) NULL,
    `encryptionIv` VARCHAR(191) NULL,
    `encryptionTag` VARCHAR(191) NULL,
    `contentHash` VARCHAR(191) NULL,
    `personalNote` TEXT NULL,
    `status` ENUM('DRAFT', 'RECORDED', 'FINALIZED', 'DELIVERED', 'EXPIRED') NOT NULL DEFAULT 'DRAFT',
    `accessToken` VARCHAR(191) NOT NULL,
    `tokenExpiresAt` DATETIME(3) NULL,
    `deliveryTrigger` VARCHAR(191) NOT NULL DEFAULT 'EXECUTOR_RELEASE',
    `inactivityDays` INTEGER NULL,
    `recordedAt` DATETIME(3) NULL,
    `finalizedAt` DATETIME(3) NULL,
    `deliveredAt` DATETIME(3) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updatedAt` DATETIME(3) NOT NULL,

    UNIQUE INDEX `VideoMessage_accessToken_key`(`accessToken`),
    INDEX `VideoMessage_userId_idx`(`userId`),
    INDEX `VideoMessage_accessToken_idx`(`accessToken`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `VideoRecipient` (
    `id` VARCHAR(191) NOT NULL,
    `videoMessageId` VARCHAR(191) NOT NULL,
    `recipientEmail` VARCHAR(191) NOT NULL,
    `recipientName` VARCHAR(191) NOT NULL,
    `accessToken` VARCHAR(191) NOT NULL,
    `status` ENUM('PENDING', 'NOTIFIED', 'VIEWED', 'EXPIRED') NOT NULL DEFAULT 'PENDING',
    `notifiedAt` DATETIME(3) NULL,
    `viewedAt` DATETIME(3) NULL,
    `viewCount` INTEGER NOT NULL DEFAULT 0,
    `ipAddress` VARCHAR(191) NULL,
    `userAgent` VARCHAR(191) NULL,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `VideoRecipient_accessToken_key`(`accessToken`),
    INDEX `VideoRecipient_videoMessageId_idx`(`videoMessageId`),
    INDEX `VideoRecipient_accessToken_idx`(`accessToken`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `BeneficiaryPortalAccess` (
    `id` VARCHAR(191) NOT NULL,
    `familyMemberId` VARCHAR(191) NOT NULL,
    `calculationId` VARCHAR(191) NOT NULL,
    `accessToken` VARCHAR(191) NOT NULL,
    `tokenExpiresAt` DATETIME(3) NOT NULL,
    `lastViewedAt` DATETIME(3) NULL,
    `viewCount` INTEGER NOT NULL DEFAULT 0,
    `createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),

    UNIQUE INDEX `BeneficiaryPortalAccess_accessToken_key`(`accessToken`),
    INDEX `BeneficiaryPortalAccess_familyMemberId_idx`(`familyMemberId`),
    INDEX `BeneficiaryPortalAccess_calculationId_idx`(`calculationId`),
    INDEX `BeneficiaryPortalAccess_accessToken_idx`(`accessToken`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `SystemSetting` (
    `id` VARCHAR(191) NOT NULL,
    `key` VARCHAR(191) NOT NULL,
    `value` VARCHAR(191) NOT NULL,
    `type` VARCHAR(191) NOT NULL DEFAULT 'string',
    `label` VARCHAR(191) NULL,
    `group` VARCHAR(191) NOT NULL DEFAULT 'general',
    `updatedAt` DATETIME(3) NOT NULL,
    `updatedBy` VARCHAR(191) NULL,

    UNIQUE INDEX `SystemSetting_key_key`(`key`),
    INDEX `SystemSetting_group_idx`(`group`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `Session` ADD CONSTRAINT `Session_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `FamilyMember` ADD CONSTRAINT `FamilyMember_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `FamilyMember` ADD CONSTRAINT `FamilyMember_parentId_fkey` FOREIGN KEY (`parentId`) REFERENCES `FamilyMember`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `FamilyMember` ADD CONSTRAINT `FamilyMember_spouseId_fkey` FOREIGN KEY (`spouseId`) REFERENCES `FamilyMember`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Asset` ADD CONSTRAINT `Asset_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Liability` ADD CONSTRAINT `Liability_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Bequest` ADD CONSTRAINT `Bequest_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Bequest` ADD CONSTRAINT `Bequest_beneficiaryId_fkey` FOREIGN KEY (`beneficiaryId`) REFERENCES `FamilyMember`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Bequest` ADD CONSTRAINT `Bequest_assetId_fkey` FOREIGN KEY (`assetId`) REFERENCES `Asset`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `InheritanceCalculation` ADD CONSTRAINT `InheritanceCalculation_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CalculationShare` ADD CONSTRAINT `CalculationShare_calculationId_fkey` FOREIGN KEY (`calculationId`) REFERENCES `InheritanceCalculation`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `CalculationShare` ADD CONSTRAINT `CalculationShare_familyMemberId_fkey` FOREIGN KEY (`familyMemberId`) REFERENCES `FamilyMember`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentPack` ADD CONSTRAINT `DocumentPack_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentPack` ADD CONSTRAINT `DocumentPack_calculationId_fkey` FOREIGN KEY (`calculationId`) REFERENCES `InheritanceCalculation`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VaultItem` ADD CONSTRAINT `VaultItem_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `EdgeCase` ADD CONSTRAINT `EdgeCase_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ProfessionalReview` ADD CONSTRAINT `ProfessionalReview_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceRequest` ADD CONSTRAINT `ServiceRequest_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ServiceRequest` ADD CONSTRAINT `ServiceRequest_professionalId_fkey` FOREIGN KEY (`professionalId`) REFERENCES `Professional`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Subscription` ADD CONSTRAINT `Subscription_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `LifeEvent` ADD CONSTRAINT `LifeEvent_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `AuditLog` ADD CONSTRAINT `AuditLog_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `OrisInteraction` ADD CONSTRAINT `OrisInteraction_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ConsentLog` ADD CONSTRAINT `ConsentLog_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ZakatCalculation` ADD CONSTRAINT `ZakatCalculation_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentIdentifier` ADD CONSTRAINT `DocumentIdentifier_documentPackId_fkey` FOREIGN KEY (`documentPackId`) REFERENCES `DocumentPack`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentIdentifier` ADD CONSTRAINT `DocumentIdentifier_calculationId_fkey` FOREIGN KEY (`calculationId`) REFERENCES `InheritanceCalculation`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `DocumentIdentifier` ADD CONSTRAINT `DocumentIdentifier_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Witness` ADD CONSTRAINT `Witness_documentPackId_fkey` FOREIGN KEY (`documentPackId`) REFERENCES `DocumentPack`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `WitnessAttestation` ADD CONSTRAINT `WitnessAttestation_witnessId_fkey` FOREIGN KEY (`witnessId`) REFERENCES `Witness`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Signature` ADD CONSTRAINT `Signature_documentPackId_fkey` FOREIGN KEY (`documentPackId`) REFERENCES `DocumentPack`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Signature` ADD CONSTRAINT `Signature_witnessId_fkey` FOREIGN KEY (`witnessId`) REFERENCES `Witness`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Signature` ADD CONSTRAINT `Signature_executorId_fkey` FOREIGN KEY (`executorId`) REFERENCES `ExecutorAppointment`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `Signature` ADD CONSTRAINT `Signature_signingSessionId_fkey` FOREIGN KEY (`signingSessionId`) REFERENCES `SigningSession`(`id`) ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `ExecutorAppointment` ADD CONSTRAINT `ExecutorAppointment_calculationId_fkey` FOREIGN KEY (`calculationId`) REFERENCES `InheritanceCalculation`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `IdentityVerification` ADD CONSTRAINT `IdentityVerification_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `SigningSession` ADD CONSTRAINT `SigningSession_documentPackId_fkey` FOREIGN KEY (`documentPackId`) REFERENCES `DocumentPack`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `SigningEvent` ADD CONSTRAINT `SigningEvent_signingSessionId_fkey` FOREIGN KEY (`signingSessionId`) REFERENCES `SigningSession`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VideoMessage` ADD CONSTRAINT `VideoMessage_userId_fkey` FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `VideoRecipient` ADD CONSTRAINT `VideoRecipient_videoMessageId_fkey` FOREIGN KEY (`videoMessageId`) REFERENCES `VideoMessage`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `BeneficiaryPortalAccess` ADD CONSTRAINT `BeneficiaryPortalAccess_familyMemberId_fkey` FOREIGN KEY (`familyMemberId`) REFERENCES `FamilyMember`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `BeneficiaryPortalAccess` ADD CONSTRAINT `BeneficiaryPortalAccess_calculationId_fkey` FOREIGN KEY (`calculationId`) REFERENCES `InheritanceCalculation`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

