-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('SUPER_ADMIN', 'USER', 'EXECUTOR', 'BENEFICIARY', 'PROFESSIONAL', 'SHARIAH_BOARD');

-- CreateEnum
CREATE TYPE "Doctrine" AS ENUM ('SUNNI_HANAFI', 'SUNNI_SHAFII', 'SUNNI_MALIKI', 'SUNNI_HANBALI', 'SHIA_JAFARI');

-- CreateEnum
CREATE TYPE "RulebookStatus" AS ENUM ('DRAFT', 'REVIEW', 'SIGNED');

-- CreateEnum
CREATE TYPE "Gender" AS ENUM ('MALE', 'FEMALE');

-- CreateEnum
CREATE TYPE "PersonStatus" AS ENUM ('ALIVE', 'DECEASED');

-- CreateEnum
CREATE TYPE "RelationshipType" AS ENUM ('SPOUSE', 'CHILD', 'PARENT', 'SIBLING', 'GRANDPARENT', 'GRANDCHILD', 'UNCLE', 'AUNT');

-- CreateEnum
CREATE TYPE "SiblingSubtype" AS ENUM ('FULL', 'HALF_PATERNAL', 'HALF_MATERNAL', 'STEP');

-- CreateEnum
CREATE TYPE "AssetCategory" AS ENUM ('IMMOVABLE_PROPERTY', 'BANK_ACCOUNT', 'FIXED_DEPOSIT', 'MUTUAL_FUND', 'STOCKS', 'GOLD_JEWELRY', 'VEHICLE', 'BUSINESS_INTEREST', 'DIGITAL_ASSET', 'INSURANCE', 'EPF_PPF', 'INTELLECTUAL_PROPERTY', 'OTHER');

-- CreateEnum
CREATE TYPE "LiabilityCategory" AS ENUM ('HOME_LOAN', 'VEHICLE_LOAN', 'PERSONAL_LOAN', 'CREDIT_CARD', 'BUSINESS_LOAN', 'GOLD_LOAN', 'ZAKAT_ARREARS', 'CHARITY_COMMITMENT', 'TAX_OBLIGATION', 'INFORMAL_DEBT', 'OTHER');

-- CreateEnum
CREATE TYPE "BequestType" AS ENUM ('SPECIFIC_AMOUNT', 'PERCENTAGE_OF_ESTATE', 'SPECIFIC_ASSET', 'CHARITY_DONATION', 'SADAQAH_JARIYAH');

-- CreateEnum
CREATE TYPE "CalculationStatus" AS ENUM ('DRAFT', 'PROVISIONAL', 'FINAL');

-- CreateEnum
CREATE TYPE "AdjustmentType" AS ENUM ('NONE', 'AWL', 'RADD');

-- CreateEnum
CREATE TYPE "DocumentPackStatus" AS ENUM ('DRAFT', 'PREVIEW', 'FINAL');

-- CreateEnum
CREATE TYPE "EdgeCaseStatus" AS ENUM ('SUBMITTED', 'ASSIGNED', 'UNDER_REVIEW', 'RESOLVED', 'ESCALATED');

-- CreateEnum
CREATE TYPE "SubscriptionPlan" AS ENUM ('ESSENTIAL', 'VAULT', 'VAULT_FAMILY', 'PROFESSIONAL', 'ENTERPRISE');

-- CreateEnum
CREATE TYPE "SubscriptionStatus" AS ENUM ('ACTIVE', 'EXPIRED', 'CANCELLED', 'TRIAL');

-- CreateEnum
CREATE TYPE "ProfessionalType" AS ENUM ('SHARIAH_SCHOLAR', 'ESTATE_LAWYER', 'TAX_ADVISOR', 'MEDIATOR', 'ADVOCATE', 'DOCUMENT_REGISTRATION', 'COURT_FILING', 'PROPERTY_MUTATION', 'STAMP_DUTY', 'ADVISORY_CONSULTATION');

-- CreateEnum
CREATE TYPE "ReviewStatus" AS ENUM ('REQUESTED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "IndianState" AS 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');

-- CreateEnum
CREATE TYPE "EmergencyAccessMethod" AS ENUM ('TIME_LOCK_INACTIVITY', 'TRUSTED_QUORUM', 'MANUAL_RELEASE', 'PREMIUM_ASSISTED');

-- CreateEnum
CREATE TYPE "LifeEventType" AS ENUM ('NEW_CHILD', 'MARRIAGE', 'DIVORCE', 'PARENT_DEATH', 'SPOUSE_DEATH', 'CHILD_DEATH', 'ASSET_ACQUIRED', 'ASSET_SOLD', 'DEBT_TAKEN', 'DEBT_SETTLED', 'MOVED_STATE', 'RETIREMENT');

-- CreateEnum
CREATE TYPE "ConsentPurpose" AS ENUM ('ESTATE_PLANNING', 'DOCUMENT_STORAGE', 'ORIS_AI_PROCESSING', 'PROFESSIONAL_REFERRAL', 'MARKETING', 'ANALYTICS');

-- CreateEnum
CREATE TYPE "WitnessStatus" AS ENUM ('INVITED', 'ACCEPTED', 'ATTESTED', 'DECLINED', 'EXPIRED');

-- CreateEnum
CREATE TYPE "SignatureType" AS ENUM ('TESTATOR', 'EXECUTOR', 'WITNESS', 'NOTARY');

-- CreateEnum
CREATE TYPE "ExecutorStatus" AS ENUM ('INVITED', 'ACCEPTED', 'ACTIVE', 'DECLINED', 'REVOKED', 'COMPLETED');

-- CreateEnum
CREATE TYPE "VerificationType" AS ENUM ('SELF_DECLARATION', 'AADHAAR_BASIC', 'AADHAAR_DIGILOCKER', 'MANUAL_UPLOAD');

-- CreateEnum
CREATE TYPE "SigningSessionStatus" AS ENUM ('CREATED', 'OTP_SENT', 'OTP_VERIFIED', 'DOCUMENT_VIEWED', 'SIGNATURE_DRAWN', 'COMPLETED', 'EXPIRED', 'FAILED');

-- CreateEnum
CREATE TYPE "SigningEventType" AS ENUM ('SESSION_CREATED', 'OTP_SENT', 'OTP_VERIFIED', 'OTP_FAILED', 'DOCUMENT_VIEWED', 'SIGNATURE_DRAWN', 'SIGNATURE_CONFIRMED', 'SIGNATURE_EMBEDDED', 'SESSION_EXPIRED');

-- CreateEnum
CREATE TYPE "SigningVerificationMethod" AS ENUM ('EMAIL_OTP', 'SMS_OTP', 'LOGGED_IN_SESSION', 'TOKEN_AUTH');

-- CreateEnum
CREATE TYPE "ServiceRequestStatus" AS ENUM ('PENDING', 'ACCEPTED', 'REJECTED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED', 'DISPUTED');

-- CreateEnum
CREATE TYPE "ZakatNGOStatus" AS ENUM ('PENDING', 'APPROVED', 'REJECTED', 'SUSPENDED');

-- CreateEnum
CREATE TYPE "AsnaafCategory" AS ENUM ('FUQARA', 'MASAKIN', 'AMIL', 'MUALLAF', 'RIQAB', 'GHARIMIN', 'FI_SABILILLAH', 'IBN_SABIL', 'GENERAL');

-- CreateEnum
CREATE TYPE "VideoMessageStatus" AS ENUM ('DRAFT', 'RECORDED', 'FINALIZED', 'DELIVERED', 'EXPIRED');

-- CreateEnum
CREATE TYPE "VideoRecipientStatus" AS ENUM ('PENDING', 'NOTIFIED', 'VIEWED', 'EXPIRED');

-- CreateTable
CREATE TABLE "User" (
    "id" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "passwordHash" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "phone" TEXT,
    "role" "UserRole" NOT NULL DEFAULT 'USER',
    "mfaEnabled" BOOLEAN NOT NULL DEFAULT false,
    "mfaSecret" TEXT,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "emailVerified" BOOLEAN NOT NULL DEFAULT false,
    "ssoProvider" TEXT,
    "lastLogin" TIMESTAMP(3),
    "state" "IndianState",
    "doctrine" "Doctrine",
    "deletedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Session" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "token" TEXT NOT NULL,
    "deviceInfo" TEXT,
    "ipAddress" TEXT,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FamilyMember" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "gender" "Gender" NOT NULL,
    "relationship" "RelationshipType" NOT NULL,
    "siblingSubtype" "SiblingSubtype",
    "status" "PersonStatus" NOT NULL DEFAULT 'ALIVE',
    "dateOfBirth" TIMESTAMP(3),
    "dateOfDeath" TIMESTAMP(3),
    "isMinor" BOOLEAN NOT NULL DEFAULT false,
    "dependencyNotes" TEXT,
    "contactEmail" TEXT,
    "contactPhone" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "parentId" TEXT,
    "spouseId" TEXT,

    CONSTRAINT "FamilyMember_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Asset" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "category" "AssetCategory" NOT NULL,
    "description" TEXT NOT NULL,
    "location" TEXT,
    "surveyNumber" TEXT,
    "ownershipPercent" DOUBLE PRECISION NOT NULL DEFAULT 100,
    "currentValue" DOUBLE PRECISION NOT NULL,
    "nomineeInfo" TEXT,
    "jointHolderInfo" TEXT,
    "documentUrls" TEXT[],
    "notes" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Asset_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Liability" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "category" "LiabilityCategory" NOT NULL,
    "description" TEXT NOT NULL,
    "lender" TEXT,
    "outstandingAmount" DOUBLE PRECISION NOT NULL,
    "interestRate" DOUBLE PRECISION,
    "emiAmount" DOUBLE PRECISION,
    "maturityDate" TIMESTAMP(3),
    "collateral" TEXT,
    "notes" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Liability_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Bequest" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "beneficiaryId" TEXT,
    "type" "BequestType" NOT NULL,
    "beneficiaryName" TEXT NOT NULL,
    "beneficiaryContact" TEXT,
    "amount" DOUBLE PRECISION,
    "percentage" DOUBLE PRECISION,
    "assetId" TEXT,
    "purpose" TEXT,
    "conditions" TEXT,
    "charityName" TEXT,
    "charityRegistration" TEXT,
    "isValidated" BOOLEAN NOT NULL DEFAULT false,
    "validationErrors" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Bequest_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "InheritanceCalculation" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "doctrine" "Doctrine" NOT NULL,
    "rulebookVersion" TEXT NOT NULL,
    "status" "CalculationStatus" NOT NULL DEFAULT 'DRAFT',
    "familySnapshot" JSONB NOT NULL,
    "assetSummary" JSONB,
    "netEstate" DOUBLE PRECISION,
    "bequestTotal" DOUBLE PRECISION,
    "distributableEstate" DOUBLE PRECISION,
    "adjustmentType" "AdjustmentType" NOT NULL DEFAULT 'NONE',
    "adjustmentDetails" JSONB,
    "calculationTrace" JSONB NOT NULL,
    "validations" JSONB NOT NULL,
    "certificateHash" TEXT,
    "tdbNodes" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "InheritanceCalculation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "CalculationShare" (
    "id" TEXT NOT NULL,
    "calculationId" TEXT NOT NULL,
    "familyMemberId" TEXT NOT NULL,
    "heirName" TEXT NOT NULL,
    "relationship" "RelationshipType" NOT NULL,
    "fraction" TEXT NOT NULL,
    "decimal" DOUBLE PRECISION NOT NULL,
    "percentage" DOUBLE PRECISION NOT NULL,
    "isFixed" BOOLEAN NOT NULL,
    "ruleIds" TEXT[],
    "citations" JSONB NOT NULL,
    "explanation" TEXT NOT NULL,
    "wasAdjusted" BOOLEAN NOT NULL DEFAULT false,
    "originalFraction" TEXT,
    "originalDecimal" DOUBLE PRECISION,

    CONSTRAINT "CalculationShare_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "DocumentPack" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "calculationId" TEXT NOT NULL,
    "status" "DocumentPackStatus" NOT NULL DEFAULT 'DRAFT',
    "packHash" TEXT,
    "verificationUrl" TEXT,
    "state" "IndianState" NOT NULL,
    "documents" JSONB NOT NULL,
    "generatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "creditConsumed" BOOLEAN NOT NULL DEFAULT false,

    CONSTRAINT "DocumentPack_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VaultItem" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "category" TEXT NOT NULL,
    "encryptedData" TEXT NOT NULL,
    "iv" TEXT NOT NULL,
    "authTag" TEXT NOT NULL,
    "metadata" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "VaultItem_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "EmergencyAccess" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "method" "EmergencyAccessMethod" NOT NULL,
    "inactivityDays" INTEGER,
    "countdownDays" INTEGER,
    "trustedPersons" JSONB,
    "quorumRequired" INTEGER,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "lastActivityAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "EmergencyAccess_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "EdgeCase" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "calculationId" TEXT,
    "ruleNodeId" TEXT NOT NULL,
    "doctrine" "Doctrine" NOT NULL,
    "familyContext" JSONB NOT NULL,
    "description" TEXT NOT NULL,
    "status" "EdgeCaseStatus" NOT NULL DEFAULT 'SUBMITTED',
    "assignedTo" TEXT,
    "resolution" TEXT,
    "resolutionRule" JSONB,
    "submittedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "resolvedAt" TIMESTAMP(3),

    CONSTRAINT "EdgeCase_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Professional" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "type" "ProfessionalType" NOT NULL,
    "name" TEXT NOT NULL,
    "credentials" TEXT NOT NULL,
    "institution" TEXT,
    "specializations" TEXT[],
    "states" "IndianState"[],
    "bio" TEXT,
    "rating" DOUBLE PRECISION NOT NULL DEFAULT 0,
    "reviewCount" INTEGER NOT NULL DEFAULT 0,
    "isVerified" BOOLEAN NOT NULL DEFAULT false,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "hourlyRate" DOUBLE PRECISION,
    "contactEmail" TEXT,
    "contactPhone" TEXT,
    "servicesOffered" TEXT[],
    "registrationStatus" TEXT NOT NULL DEFAULT 'PENDING',
    "rejectionReason" TEXT,
    "approvedAt" TIMESTAMP(3),
    "approvedBy" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Professional_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ProfessionalReview" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "professionalId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "status" "ReviewStatus" NOT NULL DEFAULT 'REQUESTED',
    "calculationId" TEXT,
    "reviewNotes" TEXT,
    "reviewDocument" TEXT,
    "amount" DOUBLE PRECISION NOT NULL,
    "paidAt" TIMESTAMP(3),
    "completedAt" TIMESTAMP(3),
    "rating" INTEGER,
    "feedback" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "ProfessionalReview_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ServiceRequest" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "professionalId" TEXT NOT NULL,
    "serviceType" "ProfessionalType" NOT NULL,
    "description" TEXT NOT NULL,
    "documents" JSONB,
    "amount" DOUBLE PRECISION NOT NULL,
    "status" "ServiceRequestStatus" NOT NULL DEFAULT 'PENDING',
    "razorpayOrderId" TEXT,
    "razorpayPaymentId" TEXT,
    "paidAt" TIMESTAMP(3),
    "acceptedAt" TIMESTAMP(3),
    "rejectedAt" TIMESTAMP(3),
    "rejectionReason" TEXT,
    "completedAt" TIMESTAMP(3),
    "cancelledAt" TIMESTAMP(3),
    "rating" INTEGER,
    "feedback" TEXT,
    "notes" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "ServiceRequest_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Subscription" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "plan" "SubscriptionPlan" NOT NULL,
    "status" "SubscriptionStatus" NOT NULL DEFAULT 'TRIAL',
    "startDate" TIMESTAMP(3) NOT NULL,
    "endDate" TIMESTAMP(3) NOT NULL,
    "creditsTotal" INTEGER NOT NULL,
    "creditsUsed" INTEGER NOT NULL DEFAULT 0,
    "seatsTotal" INTEGER NOT NULL,
    "seatsUsed" INTEGER NOT NULL DEFAULT 0,
    "razorpaySubId" TEXT,
    "razorpayPlanId" TEXT,
    "amount" DOUBLE PRECISION NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Subscription_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "LifeEvent" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "type" "LifeEventType" NOT NULL,
    "description" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "impactSummary" TEXT,
    "reviewRequired" BOOLEAN NOT NULL DEFAULT true,
    "reviewedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "LifeEvent_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "AuditLog" (
    "id" TEXT NOT NULL,
    "userId" TEXT,
    "action" TEXT NOT NULL,
    "entityType" TEXT NOT NULL,
    "entityId" TEXT,
    "beforeState" JSONB,
    "afterState" JSONB,
    "ipAddress" TEXT,
    "previousHash" TEXT,
    "hash" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "AuditLog_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "OrisInteraction" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "queryType" TEXT NOT NULL,
    "query" TEXT NOT NULL,
    "response" TEXT NOT NULL,
    "context" JSONB,
    "confidence" DOUBLE PRECISION,
    "tokensUsed" INTEGER,
    "latencyMs" INTEGER,
    "costUsd" DOUBLE PRECISION,
    "feedback" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "OrisInteraction_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ConsentLog" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "purpose" "ConsentPurpose" NOT NULL,
    "grantedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "revokedAt" TIMESTAMP(3),
    "noticeVersion" TEXT NOT NULL,
    "channel" TEXT NOT NULL DEFAULT 'web',

    CONSTRAINT "ConsentLog_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ZakatCalculation" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "doctrine" "Doctrine" NOT NULL,
    "label" TEXT,
    "encryptedData" TEXT NOT NULL,
    "iv" TEXT NOT NULL,
    "authTag" TEXT NOT NULL,
    "nisabMet" BOOLEAN NOT NULL,
    "zakatDue" DOUBLE PRECISION NOT NULL,
    "zakatYear" INTEGER NOT NULL,
    "certificateHash" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "ZakatCalculation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ZakatNGO" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "registrationNumber" TEXT,
    "fcraNumber" TEXT,
    "section80GNumber" TEXT,
    "description" TEXT NOT NULL,
    "mission" TEXT,
    "website" TEXT,
    "contactEmail" TEXT NOT NULL,
    "contactPhone" TEXT,
    "address" TEXT NOT NULL,
    "state" "IndianState" NOT NULL,
    "city" TEXT,
    "asnaafCategories" "AsnaafCategory"[],
    "status" "ZakatNGOStatus" NOT NULL DEFAULT 'PENDING',
    "isVerified" BOOLEAN NOT NULL DEFAULT false,
    "donateazyListed" BOOLEAN NOT NULL DEFAULT false,
    "donateazyId" TEXT,
    "logoUrl" TEXT,
    "socialLinks" JSONB,
    "rejectionReason" TEXT,
    "approvedAt" TIMESTAMP(3),
    "approvedBy" TEXT,
    "submittedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "ZakatNGO_pkey" PRIMARY KEY ("id")
);

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

    CONSTRAINT "DocumentIdentifier_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Witness" (
    "id" TEXT NOT NULL,
    "documentPackId" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "relationship" TEXT,
    "aadhaarLast4" TEXT,
    "token" TEXT NOT NULL,
    "tokenExpiresAt" TIMESTAMP(3) NOT NULL,
    "status" "WitnessStatus" NOT NULL DEFAULT 'INVITED',
    "invitedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "attestedAt" TIMESTAMP(3),
    "declinedAt" TIMESTAMP(3),

    CONSTRAINT "Witness_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "WitnessAttestation" (
    "id" TEXT NOT NULL,
    "witnessId" TEXT NOT NULL,
    "documentPackId" TEXT NOT NULL,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "attestedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "declaration" TEXT NOT NULL,

    CONSTRAINT "WitnessAttestation_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Signature" (
    "id" TEXT NOT NULL,
    "documentPackId" TEXT NOT NULL,
    "signerId" TEXT NOT NULL,
    "signerType" "SignatureType" NOT NULL,
    "signerName" TEXT NOT NULL,
    "signatureData" TEXT NOT NULL,
    "signatureHash" TEXT NOT NULL,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "signedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "witnessId" TEXT,
    "executorId" TEXT,
    "signingSessionId" TEXT,

    CONSTRAINT "Signature_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ExecutorAppointment" (
    "id" TEXT NOT NULL,
    "calculationId" TEXT NOT NULL,
    "executorUserId" TEXT,
    "executorName" TEXT NOT NULL,
    "executorEmail" TEXT NOT NULL,
    "executorPhone" TEXT,
    "token" TEXT NOT NULL,
    "tokenExpiresAt" TIMESTAMP(3) NOT NULL,
    "status" "ExecutorStatus" NOT NULL DEFAULT 'INVITED',
    "isPrimary" BOOLEAN NOT NULL DEFAULT false,
    "appointedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "acceptedAt" TIMESTAMP(3),
    "declinedAt" TIMESTAMP(3),

    CONSTRAINT "ExecutorAppointment_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "IdentityVerification" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "verificationType" "VerificationType" NOT NULL,
    "fullName" TEXT NOT NULL,
    "dateOfBirth" TIMESTAMP(3),
    "aadhaarLast4" TEXT,
    "aadhaarVerified" BOOLEAN NOT NULL DEFAULT false,
    "addressLine1" TEXT,
    "addressCity" TEXT,
    "addressState" TEXT,
    "addressPincode" TEXT,
    "documentUrl" TEXT,
    "verifiedAt" TIMESTAMP(3),
    "expiresAt" TIMESTAMP(3),
    "status" TEXT NOT NULL DEFAULT 'PENDING',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "IdentityVerification_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "SigningSession" (
    "id" TEXT NOT NULL,
    "documentPackId" TEXT NOT NULL,
    "signerType" "SignatureType" NOT NULL,
    "signerIdentifier" TEXT NOT NULL,
    "signerName" TEXT NOT NULL,
    "signerEmail" TEXT NOT NULL,
    "verificationMethod" "SigningVerificationMethod" NOT NULL,
    "otpHash" TEXT,
    "otpExpiresAt" TIMESTAMP(3),
    "otpAttempts" INTEGER NOT NULL DEFAULT 0,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "deviceFingerprint" JSONB,
    "status" "SigningSessionStatus" NOT NULL DEFAULT 'CREATED',
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "completedAt" TIMESTAMP(3),

    CONSTRAINT "SigningSession_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "SigningEvent" (
    "id" TEXT NOT NULL,
    "signingSessionId" TEXT NOT NULL,
    "eventType" "SigningEventType" NOT NULL,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "metadata" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "SigningEvent_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VideoMessage" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "recipientName" TEXT NOT NULL,
    "recipientEmail" TEXT NOT NULL,
    "recipientPhone" TEXT,
    "relationship" TEXT,
    "s3Key" TEXT,
    "duration" INTEGER,
    "fileSize" INTEGER,
    "mimeType" TEXT,
    "encryptionIv" TEXT,
    "encryptionTag" TEXT,
    "contentHash" TEXT,
    "personalNote" TEXT,
    "status" "VideoMessageStatus" NOT NULL DEFAULT 'DRAFT',
    "accessToken" TEXT NOT NULL,
    "tokenExpiresAt" TIMESTAMP(3),
    "deliveryTrigger" TEXT NOT NULL DEFAULT 'EXECUTOR_RELEASE',
    "inactivityDays" INTEGER,
    "recordedAt" TIMESTAMP(3),
    "finalizedAt" TIMESTAMP(3),
    "deliveredAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "VideoMessage_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "VideoRecipient" (
    "id" TEXT NOT NULL,
    "videoMessageId" TEXT NOT NULL,
    "recipientEmail" TEXT NOT NULL,
    "recipientName" TEXT NOT NULL,
    "accessToken" TEXT NOT NULL,
    "status" "VideoRecipientStatus" NOT NULL DEFAULT 'PENDING',
    "notifiedAt" TIMESTAMP(3),
    "viewedAt" TIMESTAMP(3),
    "viewCount" INTEGER NOT NULL DEFAULT 0,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "VideoRecipient_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "BeneficiaryPortalAccess" (
    "id" TEXT NOT NULL,
    "familyMemberId" TEXT NOT NULL,
    "calculationId" TEXT NOT NULL,
    "accessToken" TEXT NOT NULL,
    "tokenExpiresAt" TIMESTAMP(3) NOT NULL,
    "lastViewedAt" TIMESTAMP(3),
    "viewCount" INTEGER NOT NULL DEFAULT 0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "BeneficiaryPortalAccess_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "SystemSetting" (
    "id" TEXT NOT NULL,
    "key" TEXT NOT NULL,
    "value" TEXT NOT NULL,
    "type" TEXT NOT NULL DEFAULT 'string',
    "label" TEXT,
    "group" TEXT NOT NULL DEFAULT 'general',
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "updatedBy" TEXT,

    CONSTRAINT "SystemSetting_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Session_token_key" ON "Session"("token");

-- CreateIndex
CREATE INDEX "Session_userId_idx" ON "Session"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "FamilyMember_spouseId_key" ON "FamilyMember"("spouseId");

-- CreateIndex
CREATE INDEX "FamilyMember_userId_idx" ON "FamilyMember"("userId");

-- CreateIndex
CREATE INDEX "Asset_userId_idx" ON "Asset"("userId");

-- CreateIndex
CREATE INDEX "Liability_userId_idx" ON "Liability"("userId");

-- CreateIndex
CREATE INDEX "Bequest_userId_idx" ON "Bequest"("userId");

-- CreateIndex
CREATE INDEX "InheritanceCalculation_userId_idx" ON "InheritanceCalculation"("userId");

-- CreateIndex
CREATE INDEX "InheritanceCalculation_certificateHash_idx" ON "InheritanceCalculation"("certificateHash");

-- CreateIndex
CREATE INDEX "CalculationShare_calculationId_idx" ON "CalculationShare"("calculationId");

-- CreateIndex
CREATE INDEX "DocumentPack_userId_idx" ON "DocumentPack"("userId");

-- CreateIndex
CREATE INDEX "DocumentPack_packHash_idx" ON "DocumentPack"("packHash");

-- CreateIndex
CREATE INDEX "VaultItem_userId_idx" ON "VaultItem"("userId");

-- CreateIndex
CREATE INDEX "EdgeCase_status_idx" ON "EdgeCase"("status");

-- CreateIndex
CREATE UNIQUE INDEX "Professional_userId_key" ON "Professional"("userId");

-- CreateIndex
CREATE INDEX "ProfessionalReview_userId_idx" ON "ProfessionalReview"("userId");

-- CreateIndex
CREATE INDEX "ProfessionalReview_professionalId_idx" ON "ProfessionalReview"("professionalId");

-- CreateIndex
CREATE INDEX "ServiceRequest_userId_idx" ON "ServiceRequest"("userId");

-- CreateIndex
CREATE INDEX "ServiceRequest_professionalId_idx" ON "ServiceRequest"("professionalId");

-- CreateIndex
CREATE INDEX "ServiceRequest_status_idx" ON "ServiceRequest"("status");

-- CreateIndex
CREATE INDEX "Subscription_userId_idx" ON "Subscription"("userId");

-- CreateIndex
CREATE INDEX "LifeEvent_userId_idx" ON "LifeEvent"("userId");

-- CreateIndex
CREATE INDEX "AuditLog_userId_idx" ON "AuditLog"("userId");

-- CreateIndex
CREATE INDEX "AuditLog_entityType_entityId_idx" ON "AuditLog"("entityType", "entityId");

-- CreateIndex
CREATE INDEX "AuditLog_createdAt_idx" ON "AuditLog"("createdAt");

-- CreateIndex
CREATE INDEX "OrisInteraction_userId_idx" ON "OrisInteraction"("userId");

-- CreateIndex
CREATE INDEX "ConsentLog_userId_idx" ON "ConsentLog"("userId");

-- CreateIndex
CREATE INDEX "ZakatCalculation_userId_idx" ON "ZakatCalculation"("userId");

-- CreateIndex
CREATE INDEX "ZakatCalculation_userId_zakatYear_idx" ON "ZakatCalculation"("userId", "zakatYear");

-- CreateIndex
CREATE INDEX "ZakatNGO_status_idx" ON "ZakatNGO"("status");

-- CreateIndex
CREATE INDEX "ZakatNGO_state_idx" ON "ZakatNGO"("state");

-- CreateIndex
CREATE INDEX "ZakatNGO_donateazyListed_idx" ON "ZakatNGO"("donateazyListed");

-- CreateIndex
CREATE UNIQUE INDEX "DocumentIdentifier_din_key" ON "DocumentIdentifier"("din");

-- CreateIndex
CREATE UNIQUE INDEX "DocumentIdentifier_documentPackId_key" ON "DocumentIdentifier"("documentPackId");

-- CreateIndex
CREATE UNIQUE INDEX "DocumentIdentifier_calculationId_key" ON "DocumentIdentifier"("calculationId");

-- CreateIndex
CREATE INDEX "DocumentIdentifier_userId_idx" ON "DocumentIdentifier"("userId");

-- CreateIndex
CREATE INDEX "DocumentIdentifier_calculationId_idx" ON "DocumentIdentifier"("calculationId");

-- CreateIndex
CREATE UNIQUE INDEX "DocumentIdentifier_year_stateCode_sequence_key" ON "DocumentIdentifier"("year", "stateCode", "sequence");

-- CreateIndex
CREATE UNIQUE INDEX "Witness_token_key" ON "Witness"("token");

-- CreateIndex
CREATE INDEX "Witness_documentPackId_idx" ON "Witness"("documentPackId");

-- CreateIndex
CREATE INDEX "Witness_userId_idx" ON "Witness"("userId");

-- CreateIndex
CREATE INDEX "WitnessAttestation_witnessId_idx" ON "WitnessAttestation"("witnessId");

-- CreateIndex
CREATE INDEX "Signature_documentPackId_idx" ON "Signature"("documentPackId");

-- CreateIndex
CREATE INDEX "Signature_signerId_idx" ON "Signature"("signerId");

-- CreateIndex
CREATE INDEX "Signature_signingSessionId_idx" ON "Signature"("signingSessionId");

-- CreateIndex
CREATE UNIQUE INDEX "ExecutorAppointment_token_key" ON "ExecutorAppointment"("token");

-- CreateIndex
CREATE INDEX "ExecutorAppointment_calculationId_idx" ON "ExecutorAppointment"("calculationId");

-- CreateIndex
CREATE INDEX "ExecutorAppointment_executorUserId_idx" ON "ExecutorAppointment"("executorUserId");

-- CreateIndex
CREATE INDEX "ExecutorAppointment_executorEmail_idx" ON "ExecutorAppointment"("executorEmail");

-- CreateIndex
CREATE INDEX "IdentityVerification_userId_idx" ON "IdentityVerification"("userId");

-- CreateIndex
CREATE INDEX "SigningSession_documentPackId_idx" ON "SigningSession"("documentPackId");

-- CreateIndex
CREATE INDEX "SigningSession_signerIdentifier_idx" ON "SigningSession"("signerIdentifier");

-- CreateIndex
CREATE INDEX "SigningEvent_signingSessionId_idx" ON "SigningEvent"("signingSessionId");

-- CreateIndex
CREATE UNIQUE INDEX "VideoMessage_accessToken_key" ON "VideoMessage"("accessToken");

-- CreateIndex
CREATE INDEX "VideoMessage_userId_idx" ON "VideoMessage"("userId");

-- CreateIndex
CREATE INDEX "VideoMessage_accessToken_idx" ON "VideoMessage"("accessToken");

-- CreateIndex
CREATE UNIQUE INDEX "VideoRecipient_accessToken_key" ON "VideoRecipient"("accessToken");

-- CreateIndex
CREATE INDEX "VideoRecipient_videoMessageId_idx" ON "VideoRecipient"("videoMessageId");

-- CreateIndex
CREATE INDEX "VideoRecipient_accessToken_idx" ON "VideoRecipient"("accessToken");

-- CreateIndex
CREATE UNIQUE INDEX "BeneficiaryPortalAccess_accessToken_key" ON "BeneficiaryPortalAccess"("accessToken");

-- CreateIndex
CREATE INDEX "BeneficiaryPortalAccess_familyMemberId_idx" ON "BeneficiaryPortalAccess"("familyMemberId");

-- CreateIndex
CREATE INDEX "BeneficiaryPortalAccess_calculationId_idx" ON "BeneficiaryPortalAccess"("calculationId");

-- CreateIndex
CREATE INDEX "BeneficiaryPortalAccess_accessToken_idx" ON "BeneficiaryPortalAccess"("accessToken");

-- CreateIndex
CREATE UNIQUE INDEX "SystemSetting_key_key" ON "SystemSetting"("key");

-- CreateIndex
CREATE INDEX "SystemSetting_group_idx" ON "SystemSetting"("group");

-- 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;

