-- CreateEnum
CREATE TYPE "CompanyStatus" AS ENUM ('PENDING', 'TRIALING', 'ACTIVE', 'PAST_DUE', 'SUSPENDED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "Plan" AS ENUM ('STARTER', 'GROWTH', 'PRO');

-- CreateEnum
CREATE TYPE "BillingPeriod" AS ENUM ('MONTHLY', 'ANNUAL');

-- CreateEnum
CREATE TYPE "SubscriptionStatus" AS ENUM ('TRIALING', 'ACTIVE', 'PAST_DUE', 'CANCELLED', 'UNPAID');

-- CreateEnum
CREATE TYPE "InvoiceStatus" AS ENUM ('PENDING', 'PAID', 'FAILED', 'REFUNDED');

-- CreateEnum
CREATE TYPE "PaymentProvider" AS ENUM ('AMANPAY', 'PAYPAL');

-- CreateEnum
CREATE TYPE "PaymentStatus" AS ENUM ('PENDING', 'SUCCEEDED', 'FAILED', 'REFUNDED', 'PARTIALLY_REFUNDED');

-- CreateEnum
CREATE TYPE "PaymentType" AS ENUM ('CHARGE', 'DEPOSIT', 'REFUND');

-- CreateEnum
CREATE TYPE "EmployeeRole" AS ENUM ('OWNER', 'MANAGER', 'AGENT');

-- CreateEnum
CREATE TYPE "VehicleStatus" AS ENUM ('AVAILABLE', 'RENTED', 'MAINTENANCE', 'OUT_OF_SERVICE');

-- CreateEnum
CREATE TYPE "VehicleCategory" AS ENUM ('ECONOMY', 'COMPACT', 'MIDSIZE', 'FULLSIZE', 'SUV', 'LUXURY', 'VAN', 'TRUCK');

-- CreateEnum
CREATE TYPE "Transmission" AS ENUM ('AUTOMATIC', 'MANUAL');

-- CreateEnum
CREATE TYPE "FuelType" AS ENUM ('GASOLINE', 'DIESEL', 'ELECTRIC', 'HYBRID');

-- CreateEnum
CREATE TYPE "OfferType" AS ENUM ('PERCENTAGE', 'FIXED_AMOUNT', 'FREE_DAY', 'SPECIAL_RATE');

-- CreateEnum
CREATE TYPE "ReservationStatus" AS ENUM ('DRAFT', 'CONFIRMED', 'ACTIVE', 'COMPLETED', 'CANCELLED', 'NO_SHOW');

-- CreateEnum
CREATE TYPE "BookingSource" AS ENUM ('DASHBOARD', 'PUBLIC_SITE', 'CARPLACE', 'API');

-- CreateEnum
CREATE TYPE "CancelledBy" AS ENUM ('COMPANY', 'RENTER', 'SYSTEM');

-- CreateEnum
CREATE TYPE "LicenseStatus" AS ENUM ('PENDING', 'VALID', 'EXPIRING', 'APPROVED', 'DENIED', 'EXPIRED');

-- CreateEnum
CREATE TYPE "InsuranceType" AS ENUM ('CDW', 'SCDW', 'THEFT', 'THIRD_PARTY', 'FULL', 'BASIC', 'ROADSIDE', 'PERSONAL', 'CUSTOM');

-- CreateEnum
CREATE TYPE "InsuranceChargeType" AS ENUM ('PER_DAY', 'PER_RENTAL', 'PERCENTAGE_OF_RENTAL');

-- CreateEnum
CREATE TYPE "DamageReportType" AS ENUM ('CHECKIN', 'CHECKOUT');

-- CreateEnum
CREATE TYPE "PricingRuleType" AS ENUM ('SURCHARGE', 'DISCOUNT');

-- CreateEnum
CREATE TYPE "PricingCondition" AS ENUM ('AGE_LESS_THAN', 'AGE_GREATER_THAN', 'LICENSE_YEARS_LESS_THAN', 'LICENSE_YEARS_GREATER_THAN');

-- CreateEnum
CREATE TYPE "PriceAdjustmentType" AS ENUM ('PERCENTAGE', 'FLAT_PER_DAY', 'FLAT_TOTAL');

-- CreateEnum
CREATE TYPE "AdditionalDriverCharge" AS ENUM ('FREE', 'PER_DAY', 'FLAT');

-- CreateEnum
CREATE TYPE "FuelPolicyType" AS ENUM ('FULL_TO_FULL', 'FULL_TO_EMPTY', 'SAME_TO_SAME', 'PREPAID', 'FREE');

-- CreateEnum
CREATE TYPE "InspectionType" AS ENUM ('CHECKIN', 'CHECKOUT');

-- CreateEnum
CREATE TYPE "FuelLevel" AS ENUM ('FULL', 'SEVEN_EIGHTHS', 'THREE_QUARTERS', 'FIVE_EIGHTHS', 'HALF', 'THREE_EIGHTHS', 'QUARTER', 'ONE_EIGHTH', 'EMPTY');

-- CreateEnum
CREATE TYPE "DiagramView" AS ENUM ('TOP', 'FRONT', 'REAR', 'LEFT', 'RIGHT');

-- CreateEnum
CREATE TYPE "DamageType" AS ENUM ('SCRATCH', 'DENT', 'CRACK', 'CHIP', 'MISSING', 'STAIN', 'OTHER');

-- CreateEnum
CREATE TYPE "DamageSeverity" AS ENUM ('MINOR', 'MODERATE', 'MAJOR');

-- CreateEnum
CREATE TYPE "ReportingPeriod" AS ENUM ('WEEKLY', 'MONTHLY', 'QUARTERLY', 'ANNUAL');

-- CreateEnum
CREATE TYPE "ReportFormat" AS ENUM ('PDF', 'CSV', 'BOTH');

-- CreateEnum
CREATE TYPE "AdminRole" AS ENUM ('SUPER_ADMIN', 'ADMIN', 'SUPPORT', 'FINANCE', 'VIEWER');

-- CreateEnum
CREATE TYPE "AdminResource" AS ENUM ('COMPANIES', 'COMPANY_EMPLOYEES', 'SUBSCRIPTIONS', 'PAYMENTS', 'OFFERS', 'RENTERS', 'ADMIN_USERS', 'AUDIT_LOGS', 'PLATFORM_METRICS');

-- CreateEnum
CREATE TYPE "AdminAction" AS ENUM ('READ', 'CREATE', 'UPDATE', 'DELETE', 'SUSPEND', 'IMPERSONATE');

-- CreateEnum
CREATE TYPE "NotificationType" AS ENUM ('NEW_BOOKING', 'BOOKING_CANCELLED', 'PAYMENT_RECEIVED', 'PAYMENT_FAILED', 'SUBSCRIPTION_TRIAL_ENDING', 'SUBSCRIPTION_SUSPENDED', 'VEHICLE_MAINTENANCE_DUE', 'OFFER_EXPIRING', 'NEW_REVIEW_RECEIVED', 'BOOKING_CONFIRMED', 'PICKUP_REMINDER_24H', 'PICKUP_REMINDER_2H', 'VEHICLE_READY', 'RETURN_REMINDER', 'BOOKING_CANCELLED_BY_COMPANY', 'REFUND_PROCESSED', 'NEW_OFFER_FROM_SAVED_COMPANY', 'REVIEW_REQUEST');

-- CreateEnum
CREATE TYPE "NotificationChannel" AS ENUM ('EMAIL', 'SMS', 'WHATSAPP', 'IN_APP', 'PUSH');

-- CreateEnum
CREATE TYPE "NotificationStatus" AS ENUM ('PENDING', 'SENT', 'DELIVERED', 'FAILED', 'READ');

-- CreateTable
CREATE TABLE "companies" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "slug" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "address" JSONB,
    "status" "CompanyStatus" NOT NULL DEFAULT 'PENDING',
    "subscriptionPaymentRef" TEXT,
    "apiKey" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "subscriptions" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "plan" "Plan" NOT NULL DEFAULT 'STARTER',
    "billingPeriod" "BillingPeriod" NOT NULL DEFAULT 'MONTHLY',
    "status" "SubscriptionStatus" NOT NULL DEFAULT 'TRIALING',
    "currency" TEXT NOT NULL DEFAULT 'MAD',
    "trialStartAt" TIMESTAMP(3),
    "trialEndAt" TIMESTAMP(3),
    "currentPeriodStart" TIMESTAMP(3),
    "currentPeriodEnd" TIMESTAMP(3),
    "cancelledAt" TIMESTAMP(3),
    "cancelAtPeriodEnd" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "subscription_invoices" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "subscriptionId" TEXT NOT NULL,
    "amount" INTEGER NOT NULL,
    "currency" TEXT NOT NULL DEFAULT 'MAD',
    "status" "InvoiceStatus" NOT NULL,
    "amanpayTransactionId" TEXT,
    "paypalCaptureId" TEXT,
    "paymentProvider" "PaymentProvider" NOT NULL DEFAULT 'AMANPAY',
    "paidAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "brand_settings" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "displayName" TEXT NOT NULL,
    "tagline" TEXT,
    "logoUrl" TEXT,
    "faviconUrl" TEXT,
    "heroImageUrl" TEXT,
    "primaryColor" TEXT NOT NULL DEFAULT '#1A56DB',
    "accentColor" TEXT NOT NULL DEFAULT '#F59E0B',
    "subdomain" TEXT NOT NULL,
    "customDomain" TEXT,
    "customDomainVerified" BOOLEAN NOT NULL DEFAULT false,
    "customDomainAddedAt" TIMESTAMP(3),
    "publicEmail" TEXT,
    "publicPhone" TEXT,
    "publicAddress" TEXT,
    "publicCity" TEXT,
    "publicCountry" TEXT,
    "websiteUrl" TEXT,
    "whatsappNumber" TEXT,
    "facebookUrl" TEXT,
    "instagramUrl" TEXT,
    "defaultLocale" TEXT NOT NULL DEFAULT 'en',
    "defaultCurrency" TEXT NOT NULL DEFAULT 'MAD',
    "amanpayMerchantId" TEXT,
    "amanpaySecretKey" TEXT,
    "paypalEmail" TEXT,
    "paypalMerchantId" TEXT,
    "paymentMethodsEnabled" "PaymentProvider"[],
    "isListedOnCarplace" BOOLEAN NOT NULL DEFAULT true,
    "carplaceRating" DOUBLE PRECISION,
    "home_page_config" JSONB,
    "menu_config" JSONB,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "employees" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "clerkUserId" TEXT NOT NULL,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "passwordHash" TEXT,
    "passwordResetToken" TEXT,
    "passwordResetExpiresAt" TIMESTAMP(3),
    "role" "EmployeeRole" NOT NULL DEFAULT 'AGENT',
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "vehicles" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "make" TEXT NOT NULL,
    "model" TEXT NOT NULL,
    "year" INTEGER NOT NULL,
    "color" TEXT NOT NULL,
    "licensePlate" TEXT NOT NULL,
    "vin" TEXT,
    "category" "VehicleCategory" NOT NULL DEFAULT 'ECONOMY',
    "seats" INTEGER NOT NULL DEFAULT 5,
    "transmission" "Transmission" NOT NULL DEFAULT 'AUTOMATIC',
    "fuelType" "FuelType" NOT NULL DEFAULT 'GASOLINE',
    "features" TEXT[],
    "dailyRate" INTEGER NOT NULL,
    "status" "VehicleStatus" NOT NULL DEFAULT 'AVAILABLE',
    "photos" TEXT[],
    "mileage" INTEGER,
    "notes" TEXT,
    "isPublished" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "offers" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "termsAndConds" TEXT,
    "imageUrl" TEXT,
    "type" "OfferType" NOT NULL,
    "discountValue" INTEGER NOT NULL,
    "specialRate" INTEGER,
    "appliesToAll" BOOLEAN NOT NULL DEFAULT true,
    "categories" "VehicleCategory"[],
    "minRentalDays" INTEGER,
    "maxRentalDays" INTEGER,
    "promoCode" TEXT,
    "maxRedemptions" INTEGER,
    "redemptionCount" INTEGER NOT NULL DEFAULT 0,
    "validFrom" TIMESTAMP(3) NOT NULL,
    "validUntil" TIMESTAMP(3) NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "isPublic" BOOLEAN NOT NULL DEFAULT true,
    "isFeatured" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "offer_vehicles" (
    "offerId" TEXT NOT NULL,
    "vehicleId" TEXT NOT NULL,

    CONSTRAINT "offer_vehicles_pkey" PRIMARY KEY ("offerId","vehicleId")
);

-- CreateTable
CREATE TABLE "renters" (
    "id" TEXT NOT NULL,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "passwordHash" TEXT NOT NULL,
    "driverLicense" TEXT,
    "dateOfBirth" TIMESTAMP(3),
    "nationality" TEXT,
    "preferredLocale" TEXT NOT NULL DEFAULT 'en',
    "preferredCurrency" TEXT NOT NULL DEFAULT 'MAD',
    "fcmToken" TEXT,
    "emailVerified" BOOLEAN NOT NULL DEFAULT false,
    "phoneVerified" BOOLEAN NOT NULL DEFAULT false,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "renter_saved_companies" (
    "renterId" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "savedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "renter_saved_companies_pkey" PRIMARY KEY ("renterId","companyId")
);

-- CreateTable
CREATE TABLE "customers" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "renterId" TEXT,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "phone" TEXT,
    "driverLicense" TEXT,
    "dateOfBirth" TIMESTAMP(3),
    "nationality" TEXT,
    "address" JSONB,
    "notes" TEXT,
    "flagged" BOOLEAN NOT NULL DEFAULT false,
    "flagReason" TEXT,
    "licenseExpiry" TIMESTAMP(3),
    "licenseIssuedAt" TIMESTAMP(3),
    "licenseCountry" TEXT,
    "licenseNumber" TEXT,
    "licenseCategory" TEXT,
    "licenseExpired" BOOLEAN NOT NULL DEFAULT false,
    "licenseExpiringSoon" BOOLEAN NOT NULL DEFAULT false,
    "licenseValidationStatus" "LicenseStatus" NOT NULL DEFAULT 'PENDING',
    "licenseApprovedBy" TEXT,
    "licenseApprovedAt" TIMESTAMP(3),
    "licenseApprovalNote" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "reservations" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "vehicleId" TEXT NOT NULL,
    "customerId" TEXT NOT NULL,
    "renterId" TEXT,
    "offerId" TEXT,
    "promoCodeUsed" TEXT,
    "source" "BookingSource" NOT NULL DEFAULT 'DASHBOARD',
    "carplaceRef" TEXT,
    "status" "ReservationStatus" NOT NULL DEFAULT 'DRAFT',
    "startDate" TIMESTAMP(3) NOT NULL,
    "endDate" TIMESTAMP(3) NOT NULL,
    "pickupLocation" TEXT,
    "returnLocation" TEXT,
    "dailyRate" INTEGER NOT NULL,
    "discountAmount" INTEGER NOT NULL DEFAULT 0,
    "totalDays" INTEGER NOT NULL,
    "totalAmount" INTEGER NOT NULL,
    "depositAmount" INTEGER NOT NULL DEFAULT 0,
    "paymentStatus" TEXT NOT NULL DEFAULT 'UNPAID',
    "paidAmount" INTEGER NOT NULL DEFAULT 0,
    "checkedInAt" TIMESTAMP(3),
    "checkedOutAt" TIMESTAMP(3),
    "checkInMileage" INTEGER,
    "checkOutMileage" INTEGER,
    "notes" TEXT,
    "cancelReason" TEXT,
    "cancelledBy" "CancelledBy",
    "contractNumber" TEXT,
    "invoiceNumber" TEXT,
    "checkInFuelLevel" TEXT,
    "checkOutFuelLevel" TEXT,
    "insuranceTotal" INTEGER NOT NULL DEFAULT 0,
    "additionalDriverTotal" INTEGER NOT NULL DEFAULT 0,
    "pricingRulesApplied" JSONB,
    "pricingRulesTotal" INTEGER NOT NULL DEFAULT 0,
    "damageChargeAmount" INTEGER,
    "damageChargeNote" TEXT,
    "extras" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "rental_payments" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "amount" INTEGER NOT NULL,
    "currency" TEXT NOT NULL DEFAULT 'MAD',
    "status" "PaymentStatus" NOT NULL DEFAULT 'PENDING',
    "type" "PaymentType" NOT NULL DEFAULT 'CHARGE',
    "paymentProvider" "PaymentProvider" NOT NULL,
    "amanpayTransactionId" TEXT,
    "paypalCaptureId" TEXT,
    "paymentMethod" TEXT,
    "paidAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "reviews" (
    "id" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "renterId" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "overallRating" INTEGER NOT NULL,
    "vehicleRating" INTEGER,
    "serviceRating" INTEGER,
    "comment" TEXT,
    "isPublished" BOOLEAN NOT NULL DEFAULT true,
    "companyReply" TEXT,
    "companyRepliedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "notifications" (
    "id" TEXT NOT NULL,
    "companyId" TEXT,
    "employeeId" TEXT,
    "renterId" TEXT,
    "type" "NotificationType" NOT NULL,
    "title" TEXT NOT NULL,
    "body" TEXT NOT NULL,
    "data" JSONB,
    "channel" "NotificationChannel" NOT NULL,
    "status" "NotificationStatus" NOT NULL DEFAULT 'PENDING',
    "sentAt" TIMESTAMP(3),
    "failReason" TEXT,
    "readAt" TIMESTAMP(3),
    "providerMessageId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "notification_preferences" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT,
    "renterId" TEXT,
    "notificationType" "NotificationType" NOT NULL,
    "channel" "NotificationChannel" NOT NULL,
    "enabled" BOOLEAN NOT NULL DEFAULT true,

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

-- CreateTable
CREATE TABLE "maintenance_logs" (
    "id" TEXT NOT NULL,
    "vehicleId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "description" TEXT,
    "cost" INTEGER,
    "mileage" INTEGER,
    "performedAt" TIMESTAMP(3) NOT NULL,
    "nextDueAt" TIMESTAMP(3),
    "nextDueMileage" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "contract_settings" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "legalName" TEXT,
    "registrationNumber" TEXT,
    "taxId" TEXT,
    "terms" TEXT NOT NULL DEFAULT '',
    "fuelPolicy" TEXT NOT NULL DEFAULT 'The vehicle must be returned with the same fuel level as at pickup.',
    "depositPolicy" TEXT NOT NULL DEFAULT 'The security deposit is refundable within 7 days after return, subject to vehicle inspection.',
    "lateFeePolicy" TEXT NOT NULL DEFAULT 'Late returns will incur a charge of 1 additional day rate per hour of delay.',
    "damagePolicy" TEXT NOT NULL DEFAULT 'The renter is liable for any damage not covered by insurance.',
    "additionalClauses" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "signatureRequired" BOOLEAN NOT NULL DEFAULT true,
    "contractFooterNote" TEXT,
    "invoiceFooterNote" TEXT,
    "showTax" BOOLEAN NOT NULL DEFAULT false,
    "taxRate" DOUBLE PRECISION,
    "taxLabel" TEXT,
    "contractPrefix" TEXT NOT NULL DEFAULT 'CNT',
    "invoicePrefix" TEXT NOT NULL DEFAULT 'INV',
    "fuelPolicyType" "FuelPolicyType" NOT NULL DEFAULT 'FULL_TO_FULL',
    "fuelPolicyNote" TEXT,
    "fuelChargePerLiter" INTEGER,
    "fuelShortfallFee" INTEGER,
    "lateFeePerHour" INTEGER,
    "taxLines" JSONB,
    "lastContractSeq" INTEGER NOT NULL DEFAULT 0,
    "lastInvoiceSeq" INTEGER NOT NULL DEFAULT 0,
    "additionalDriverCharge" "AdditionalDriverCharge" NOT NULL DEFAULT 'FREE',
    "additionalDriverDailyRate" INTEGER NOT NULL DEFAULT 0,
    "additionalDriverFlatRate" INTEGER NOT NULL DEFAULT 0,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "insurance_policies" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "type" "InsuranceType" NOT NULL,
    "chargeType" "InsuranceChargeType" NOT NULL,
    "chargeValue" INTEGER NOT NULL,
    "isRequired" BOOLEAN NOT NULL DEFAULT false,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "sortOrder" INTEGER NOT NULL DEFAULT 0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "reservation_insurances" (
    "id" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "insurancePolicyId" TEXT NOT NULL,
    "policyName" TEXT NOT NULL,
    "policyType" "InsuranceType" NOT NULL,
    "chargeType" "InsuranceChargeType" NOT NULL,
    "chargeValue" INTEGER NOT NULL,
    "totalCharge" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "additional_drivers" (
    "id" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "email" TEXT,
    "phone" TEXT,
    "driverLicense" TEXT NOT NULL,
    "licenseExpiry" TIMESTAMP(3),
    "licenseIssuedAt" TIMESTAMP(3),
    "dateOfBirth" TIMESTAMP(3),
    "nationality" TEXT,
    "chargeType" "AdditionalDriverCharge" NOT NULL DEFAULT 'FREE',
    "chargeValue" INTEGER NOT NULL DEFAULT 0,
    "totalCharge" INTEGER NOT NULL DEFAULT 0,
    "licenseExpired" BOOLEAN NOT NULL DEFAULT false,
    "licenseExpiringSoon" BOOLEAN NOT NULL DEFAULT false,
    "requiresApproval" BOOLEAN NOT NULL DEFAULT false,
    "approvedBy" TEXT,
    "approvedAt" TIMESTAMP(3),
    "approvalNote" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "damage_reports" (
    "id" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "type" "DamageReportType" NOT NULL,
    "damages" JSONB NOT NULL,
    "photos" TEXT[],
    "fuelLevel" "FuelLevel" NOT NULL DEFAULT 'FULL',
    "mileage" INTEGER,
    "inspectedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "inspectedBy" TEXT,
    "customerSignedAt" TIMESTAMP(3),
    "customerName" TEXT,

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

-- CreateTable
CREATE TABLE "damage_inspections" (
    "id" TEXT NOT NULL,
    "reservationId" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "type" "InspectionType" NOT NULL,
    "mileage" INTEGER,
    "fuelLevel" "FuelLevel" NOT NULL,
    "fuelCharge" INTEGER,
    "generalCondition" TEXT,
    "employeeNotes" TEXT,
    "customerAgreed" BOOLEAN NOT NULL DEFAULT false,
    "inspectedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "inspectedBy" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "damage_points" (
    "id" TEXT NOT NULL,
    "inspectionId" TEXT NOT NULL,
    "viewType" "DiagramView" NOT NULL,
    "x" DOUBLE PRECISION NOT NULL,
    "y" DOUBLE PRECISION NOT NULL,
    "damageType" "DamageType" NOT NULL,
    "severity" "DamageSeverity" NOT NULL DEFAULT 'MINOR',
    "description" TEXT,
    "isPreExisting" BOOLEAN NOT NULL DEFAULT false,

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

-- CreateTable
CREATE TABLE "pricing_rules" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "type" "PricingRuleType" NOT NULL,
    "condition" "PricingCondition" NOT NULL,
    "conditionValue" INTEGER NOT NULL,
    "adjustmentType" "PriceAdjustmentType" NOT NULL,
    "adjustmentValue" INTEGER NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "description" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "accounting_settings" (
    "id" TEXT NOT NULL,
    "companyId" TEXT NOT NULL,
    "reportingPeriod" "ReportingPeriod" NOT NULL DEFAULT 'MONTHLY',
    "fiscalYearStart" INTEGER NOT NULL DEFAULT 1,
    "currency" TEXT NOT NULL DEFAULT 'MAD',
    "accountantEmail" TEXT,
    "accountantName" TEXT,
    "autoSendReport" BOOLEAN NOT NULL DEFAULT false,
    "reportFormat" "ReportFormat" NOT NULL DEFAULT 'PDF',
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "admin_users" (
    "id" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "firstName" TEXT NOT NULL,
    "lastName" TEXT NOT NULL,
    "passwordHash" TEXT NOT NULL,
    "role" "AdminRole" NOT NULL DEFAULT 'SUPPORT',
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "totpSecret" TEXT,
    "totpEnabled" BOOLEAN NOT NULL DEFAULT false,
    "lastLoginAt" TIMESTAMP(3),
    "lastLoginIp" TEXT,
    "passwordResetToken" TEXT,
    "passwordResetExpiresAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "admin_permissions" (
    "id" TEXT NOT NULL,
    "adminUserId" TEXT NOT NULL,
    "resource" "AdminResource" NOT NULL,
    "actions" "AdminAction"[],

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

-- CreateTable
CREATE TABLE "audit_logs" (
    "id" TEXT NOT NULL,
    "adminUserId" TEXT NOT NULL,
    "action" TEXT NOT NULL,
    "resource" TEXT NOT NULL,
    "resourceId" TEXT,
    "companyId" TEXT,
    "before" JSONB,
    "after" JSONB,
    "ipAddress" TEXT,
    "userAgent" TEXT,
    "note" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "companies_slug_key" ON "companies"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "companies_email_key" ON "companies"("email");

-- CreateIndex
CREATE UNIQUE INDEX "companies_apiKey_key" ON "companies"("apiKey");

-- CreateIndex
CREATE UNIQUE INDEX "subscriptions_companyId_key" ON "subscriptions"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "subscription_invoices_amanpayTransactionId_key" ON "subscription_invoices"("amanpayTransactionId");

-- CreateIndex
CREATE UNIQUE INDEX "subscription_invoices_paypalCaptureId_key" ON "subscription_invoices"("paypalCaptureId");

-- CreateIndex
CREATE INDEX "subscription_invoices_companyId_idx" ON "subscription_invoices"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "brand_settings_companyId_key" ON "brand_settings"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "brand_settings_subdomain_key" ON "brand_settings"("subdomain");

-- CreateIndex
CREATE UNIQUE INDEX "brand_settings_customDomain_key" ON "brand_settings"("customDomain");

-- CreateIndex
CREATE UNIQUE INDEX "employees_clerkUserId_key" ON "employees"("clerkUserId");

-- CreateIndex
CREATE UNIQUE INDEX "employees_passwordResetToken_key" ON "employees"("passwordResetToken");

-- CreateIndex
CREATE INDEX "employees_companyId_idx" ON "employees"("companyId");

-- CreateIndex
CREATE INDEX "vehicles_companyId_idx" ON "vehicles"("companyId");

-- CreateIndex
CREATE INDEX "vehicles_companyId_status_idx" ON "vehicles"("companyId", "status");

-- CreateIndex
CREATE INDEX "vehicles_companyId_isPublished_idx" ON "vehicles"("companyId", "isPublished");

-- CreateIndex
CREATE UNIQUE INDEX "offers_promoCode_key" ON "offers"("promoCode");

-- CreateIndex
CREATE INDEX "offers_companyId_idx" ON "offers"("companyId");

-- CreateIndex
CREATE INDEX "offers_isPublic_isActive_validUntil_idx" ON "offers"("isPublic", "isActive", "validUntil");

-- CreateIndex
CREATE UNIQUE INDEX "renters_email_key" ON "renters"("email");

-- CreateIndex
CREATE INDEX "customers_companyId_idx" ON "customers"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "customers_companyId_email_key" ON "customers"("companyId", "email");

-- CreateIndex
CREATE UNIQUE INDEX "reservations_contractNumber_key" ON "reservations"("contractNumber");

-- CreateIndex
CREATE UNIQUE INDEX "reservations_invoiceNumber_key" ON "reservations"("invoiceNumber");

-- CreateIndex
CREATE INDEX "reservations_companyId_idx" ON "reservations"("companyId");

-- CreateIndex
CREATE INDEX "reservations_companyId_status_idx" ON "reservations"("companyId", "status");

-- CreateIndex
CREATE INDEX "reservations_vehicleId_startDate_endDate_idx" ON "reservations"("vehicleId", "startDate", "endDate");

-- CreateIndex
CREATE INDEX "reservations_renterId_idx" ON "reservations"("renterId");

-- CreateIndex
CREATE UNIQUE INDEX "rental_payments_amanpayTransactionId_key" ON "rental_payments"("amanpayTransactionId");

-- CreateIndex
CREATE UNIQUE INDEX "rental_payments_paypalCaptureId_key" ON "rental_payments"("paypalCaptureId");

-- CreateIndex
CREATE INDEX "rental_payments_companyId_idx" ON "rental_payments"("companyId");

-- CreateIndex
CREATE INDEX "rental_payments_reservationId_idx" ON "rental_payments"("reservationId");

-- CreateIndex
CREATE UNIQUE INDEX "reviews_reservationId_key" ON "reviews"("reservationId");

-- CreateIndex
CREATE INDEX "reviews_companyId_idx" ON "reviews"("companyId");

-- CreateIndex
CREATE INDEX "notifications_companyId_idx" ON "notifications"("companyId");

-- CreateIndex
CREATE INDEX "notifications_renterId_idx" ON "notifications"("renterId");

-- CreateIndex
CREATE UNIQUE INDEX "notification_preferences_employeeId_notificationType_channe_key" ON "notification_preferences"("employeeId", "notificationType", "channel");

-- CreateIndex
CREATE UNIQUE INDEX "notification_preferences_renterId_notificationType_channel_key" ON "notification_preferences"("renterId", "notificationType", "channel");

-- CreateIndex
CREATE INDEX "maintenance_logs_vehicleId_idx" ON "maintenance_logs"("vehicleId");

-- CreateIndex
CREATE UNIQUE INDEX "contract_settings_companyId_key" ON "contract_settings"("companyId");

-- CreateIndex
CREATE INDEX "insurance_policies_companyId_idx" ON "insurance_policies"("companyId");

-- CreateIndex
CREATE INDEX "insurance_policies_companyId_isActive_idx" ON "insurance_policies"("companyId", "isActive");

-- CreateIndex
CREATE UNIQUE INDEX "reservation_insurances_reservationId_insurancePolicyId_key" ON "reservation_insurances"("reservationId", "insurancePolicyId");

-- CreateIndex
CREATE INDEX "additional_drivers_reservationId_idx" ON "additional_drivers"("reservationId");

-- CreateIndex
CREATE INDEX "additional_drivers_companyId_idx" ON "additional_drivers"("companyId");

-- CreateIndex
CREATE INDEX "damage_reports_companyId_idx" ON "damage_reports"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "damage_reports_reservationId_type_key" ON "damage_reports"("reservationId", "type");

-- CreateIndex
CREATE INDEX "damage_inspections_reservationId_idx" ON "damage_inspections"("reservationId");

-- CreateIndex
CREATE INDEX "damage_inspections_companyId_idx" ON "damage_inspections"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "damage_inspections_reservationId_type_key" ON "damage_inspections"("reservationId", "type");

-- CreateIndex
CREATE INDEX "damage_points_inspectionId_idx" ON "damage_points"("inspectionId");

-- CreateIndex
CREATE INDEX "pricing_rules_companyId_idx" ON "pricing_rules"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "accounting_settings_companyId_key" ON "accounting_settings"("companyId");

-- CreateIndex
CREATE UNIQUE INDEX "admin_users_email_key" ON "admin_users"("email");

-- CreateIndex
CREATE UNIQUE INDEX "admin_users_passwordResetToken_key" ON "admin_users"("passwordResetToken");

-- CreateIndex
CREATE UNIQUE INDEX "admin_permissions_adminUserId_resource_key" ON "admin_permissions"("adminUserId", "resource");

-- CreateIndex
CREATE INDEX "audit_logs_adminUserId_idx" ON "audit_logs"("adminUserId");

-- CreateIndex
CREATE INDEX "audit_logs_companyId_idx" ON "audit_logs"("companyId");

-- CreateIndex
CREATE INDEX "audit_logs_action_idx" ON "audit_logs"("action");

-- AddForeignKey
ALTER TABLE "subscriptions" ADD CONSTRAINT "subscriptions_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "subscription_invoices" ADD CONSTRAINT "subscription_invoices_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "subscription_invoices" ADD CONSTRAINT "subscription_invoices_subscriptionId_fkey" FOREIGN KEY ("subscriptionId") REFERENCES "subscriptions"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "brand_settings" ADD CONSTRAINT "brand_settings_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employees" ADD CONSTRAINT "employees_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "vehicles" ADD CONSTRAINT "vehicles_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "offers" ADD CONSTRAINT "offers_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "offer_vehicles" ADD CONSTRAINT "offer_vehicles_offerId_fkey" FOREIGN KEY ("offerId") REFERENCES "offers"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "offer_vehicles" ADD CONSTRAINT "offer_vehicles_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "renter_saved_companies" ADD CONSTRAINT "renter_saved_companies_renterId_fkey" FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "customers" ADD CONSTRAINT "customers_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservations" ADD CONSTRAINT "reservations_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservations" ADD CONSTRAINT "reservations_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservations" ADD CONSTRAINT "reservations_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customers"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservations" ADD CONSTRAINT "reservations_renterId_fkey" FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservations" ADD CONSTRAINT "reservations_offerId_fkey" FOREIGN KEY ("offerId") REFERENCES "offers"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rental_payments" ADD CONSTRAINT "rental_payments_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rental_payments" ADD CONSTRAINT "rental_payments_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reviews" ADD CONSTRAINT "reviews_renterId_fkey" FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_renterId_fkey" FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "notification_preferences" ADD CONSTRAINT "notification_preferences_renterId_fkey" FOREIGN KEY ("renterId") REFERENCES "renters"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "maintenance_logs" ADD CONSTRAINT "maintenance_logs_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "contract_settings" ADD CONSTRAINT "contract_settings_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "insurance_policies" ADD CONSTRAINT "insurance_policies_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservation_insurances" ADD CONSTRAINT "reservation_insurances_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "reservation_insurances" ADD CONSTRAINT "reservation_insurances_insurancePolicyId_fkey" FOREIGN KEY ("insurancePolicyId") REFERENCES "insurance_policies"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "additional_drivers" ADD CONSTRAINT "additional_drivers_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_reports" ADD CONSTRAINT "damage_reports_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_inspections" ADD CONSTRAINT "damage_inspections_reservationId_fkey" FOREIGN KEY ("reservationId") REFERENCES "reservations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_points" ADD CONSTRAINT "damage_points_inspectionId_fkey" FOREIGN KEY ("inspectionId") REFERENCES "damage_inspections"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "pricing_rules" ADD CONSTRAINT "pricing_rules_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "accounting_settings" ADD CONSTRAINT "accounting_settings_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "companies"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "admin_permissions" ADD CONSTRAINT "admin_permissions_adminUserId_fkey" FOREIGN KEY ("adminUserId") REFERENCES "admin_users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_adminUserId_fkey" FOREIGN KEY ("adminUserId") REFERENCES "admin_users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
