CREATE TYPE "public"."AdminRole" AS ENUM('ADMIN', 'SUPER_ADMIN');--> statement-breakpoint
CREATE TYPE "public"."AuditAction" AS ENUM('LOGIN', 'LOGOUT', 'LOGIN_FAILED', 'PASSWORD_CHANGE', 'EMAIL_CHANGE', 'MFA_ENABLED', 'MFA_DISABLED', 'MFA_VERIFIED', 'MFA_FAILED', 'DEVICE_TRUSTED', 'DEVICE_REMOVED', 'ROLE_CHANGED', 'PROFILE_UPDATED', 'SESSION_REVOKED');--> statement-breakpoint
CREATE TYPE "public"."BookingFrequency" AS ENUM('WEEKLY', 'BIWEEKLY', 'MONTHLY', 'SEASONAL', 'YEARLY');--> statement-breakpoint
CREATE TYPE "public"."BookingType" AS ENUM('SINGLE', 'RECURRING', 'GROUP');--> statement-breakpoint
CREATE TYPE "public"."CustomerTier" AS ENUM('BRONZE', 'SILVER', 'GOLD', 'PLATINUM');--> statement-breakpoint
CREATE TYPE "public"."DeviceType" AS ENUM('MOBILE', 'DESKTOP', 'TABLET');--> statement-breakpoint
CREATE TYPE "public"."PackageStatus" AS ENUM('ACTIVE', 'INACTIVE', 'ARCHIVED');--> statement-breakpoint
CREATE TYPE "public"."ReservationStatus" AS ENUM('PENDING', 'CONFIRMED', 'COMPLETED', 'CANCELLED');--> statement-breakpoint
CREATE TYPE "public"."ReviewStatus" AS ENUM('PENDING', 'APPROVED', 'REJECTED');--> statement-breakpoint
CREATE TYPE "public"."ServiceType" AS ENUM('BOOT_FITTING', 'SKI_SERVICE', 'BIKE_SERVICE');--> statement-breakpoint
CREATE TYPE "public"."TwoFactorType" AS ENUM('TOTP', 'SMS', 'EMAIL');--> statement-breakpoint
CREATE TABLE "CustomerLoyalty" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customerId" uuid NOT NULL,
	"points" integer DEFAULT 0,
	"totalSpent" numeric(10, 2) DEFAULT '0',
	"tier" "CustomerTier" DEFAULT 'BRONZE',
	"tierSince" timestamp DEFAULT now() NOT NULL,
	"lastActivityDate" timestamp,
	"birthdayOfferUsed" boolean DEFAULT false,
	"anniversaryOfferUsed" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "CustomerLoyalty_customerId_key" UNIQUE("customerId")
);
--> statement-breakpoint
CREATE TABLE "CustomerOffer" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"loyaltyId" uuid NOT NULL,
	"offerType" text NOT NULL,
	"title" text NOT NULL,
	"description" text NOT NULL,
	"discountPercent" integer,
	"discountAmount" numeric(10, 2),
	"validFrom" timestamp NOT NULL,
	"validUntil" timestamp NOT NULL,
	"isUsed" boolean DEFAULT false,
	"usedAt" timestamp,
	"reservationId" uuid,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "CustomerSegment" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"criteria" json NOT NULL,
	"type" text,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "CustomerSegmentMember" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"segmentId" uuid NOT NULL,
	"customerId" uuid NOT NULL,
	"addedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "CustomerSegmentMember_segmentId_customerId_key" UNIQUE("segmentId","customerId")
);
--> statement-breakpoint
CREATE TABLE "Customer" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"email" text NOT NULL,
	"phone" text NOT NULL,
	"notes" text,
	"totalReservations" integer DEFAULT 0,
	"lastReservationDate" timestamp,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	"birthday" timestamp,
	"marketingConsent" boolean DEFAULT false,
	"preferredLanguage" text DEFAULT 'ro',
	CONSTRAINT "Customer_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "DataConsent" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"email" text NOT NULL,
	"consentType" text NOT NULL,
	"consentGiven" boolean NOT NULL,
	"ipAddress" text,
	"userAgent" text,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"revokedAt" timestamp
);
--> statement-breakpoint
CREATE TABLE "DataDeletionRequest" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"email" text NOT NULL,
	"requestType" text NOT NULL,
	"status" text DEFAULT 'pending' NOT NULL,
	"requestedAt" timestamp DEFAULT now() NOT NULL,
	"processedAt" timestamp,
	"completedAt" timestamp,
	"data" json
);
--> statement-breakpoint
CREATE TABLE "LoyaltyPointsHistory" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"loyaltyId" uuid NOT NULL,
	"points" integer NOT NULL,
	"reason" text NOT NULL,
	"reservationId" uuid,
	"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "PackagePurchase" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customerId" uuid NOT NULL,
	"packageId" uuid NOT NULL,
	"purchasePrice" numeric(10, 2) NOT NULL,
	"usedCount" integer DEFAULT 0,
	"maxUses" integer NOT NULL,
	"expiresAt" timestamp,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "Service" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"code" text NOT NULL,
	"nameRo" text NOT NULL,
	"nameEn" text NOT NULL,
	"descriptionRo" text,
	"descriptionEn" text,
	"icon" text DEFAULT 'Settings',
	"color" text DEFAULT '#3b82f6',
	"duration" integer DEFAULT 60,
	"basePrice" numeric(10, 2),
	"serviceType" "ServiceType" DEFAULT 'BOOT_FITTING',
	"isActive" boolean DEFAULT true,
	"sortOrder" integer DEFAULT 0,
	"metadata" json,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "Service_code_key" UNIQUE("code")
);
--> statement-breakpoint
CREATE TABLE "ServicePackage" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"services" json NOT NULL,
	"basePrice" numeric(10, 2) NOT NULL,
	"discountPercent" integer DEFAULT 0,
	"isActive" boolean DEFAULT true,
	"validityDays" integer,
	"maxUses" integer,
	"status" "PackageStatus" DEFAULT 'ACTIVE',
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ServicePackageItem" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"servicePackageId" uuid NOT NULL,
	"serviceId" uuid NOT NULL,
	"quantity" integer DEFAULT 1,
	"discountPercent" numeric(5, 2),
	"createdAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "ServicePackageItem_servicePackageId_serviceId_key" UNIQUE("servicePackageId","serviceId")
);
--> statement-breakpoint
CREATE TABLE "ServicePricing" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serviceType" "ServiceType" NOT NULL,
	"basePrice" numeric(10, 2) NOT NULL,
	"costPrice" numeric(10, 2),
	"duration" integer NOT NULL,
	"description" text,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "ServicePricing_serviceType_key" UNIQUE("serviceType")
);
--> statement-breakpoint
CREATE TABLE "RecurringBooking" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customerId" uuid NOT NULL,
	"serviceType" "ServiceType" NOT NULL,
	"frequency" "BookingFrequency" NOT NULL,
	"dayOfWeek" integer,
	"dayOfMonth" integer,
	"preferredTime" text NOT NULL,
	"startDate" timestamp NOT NULL,
	"endDate" timestamp,
	"isActive" boolean DEFAULT true,
	"notes" text,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "Reservation" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customerName" text NOT NULL,
	"customerEmail" text NOT NULL,
	"customerPhone" text NOT NULL,
	"customerId" uuid,
	"serviceType" "ServiceType" NOT NULL,
	"date" text NOT NULL,
	"time" text NOT NULL,
	"utcDateTime" timestamp,
	"businessTimezone" text DEFAULT 'Europe/Bucharest',
	"customerTimezone" text,
	"notes" text,
	"status" "ReservationStatus" DEFAULT 'PENDING',
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	"bookingType" "BookingType" DEFAULT 'SINGLE',
	"discountApplied" numeric(10, 2),
	"groupSize" integer,
	"recurringBookingId" uuid,
	"servicePackageId" uuid,
	"servicePrice" numeric(10, 2),
	"totalAmount" numeric(10, 2),
	"serviceId" uuid,
	CONSTRAINT "Reservation_date_time_key" UNIQUE("date","time")
);
--> statement-breakpoint
CREATE TABLE "WaitingList" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"customerId" uuid NOT NULL,
	"serviceType" "ServiceType" NOT NULL,
	"preferredDate" text NOT NULL,
	"preferredTime" text NOT NULL,
	"flexibleTime" boolean DEFAULT false,
	"priority" integer DEFAULT 0,
	"isActive" boolean DEFAULT true,
	"notified" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "Review" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"author" text NOT NULL,
	"rating" integer DEFAULT 5,
	"text" text NOT NULL,
	"serviceType" "ServiceType" NOT NULL,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"customerEmail" text,
	"flaggedCount" integer DEFAULT 0,
	"isVisible" boolean DEFAULT false,
	"moderatedAt" timestamp,
	"moderatedBy" text,
	"moderatorNotes" text,
	"reservationId" uuid,
	"status" "ReviewStatus" DEFAULT 'PENDING',
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "Admin" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"username" text NOT NULL,
	"email" text NOT NULL,
	"password" text NOT NULL,
	"role" text DEFAULT 'admin',
	"isActive" boolean DEFAULT true,
	"lastLoginAt" timestamp,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "Admin_username_key" UNIQUE("username"),
	CONSTRAINT "Admin_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "AuditLog" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"action" text NOT NULL,
	"entityType" text NOT NULL,
	"entityId" uuid,
	"userId" uuid,
	"email" text,
	"metadata" json,
	"ipAddress" text,
	"userAgent" text,
	"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "BusinessMetrics" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"date" text NOT NULL,
	"totalRevenue" numeric(10, 2) DEFAULT '0',
	"totalCosts" numeric(10, 2) DEFAULT '0',
	"totalProfit" numeric(10, 2) DEFAULT '0',
	"reservationCount" integer DEFAULT 0,
	"newCustomers" integer DEFAULT 0,
	"returningCustomers" integer DEFAULT 0,
	"averageServiceValue" numeric(10, 2) DEFAULT '0',
	"customerLifetimeValue" numeric(10, 2) DEFAULT '0',
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "BusinessMetrics_date_key" UNIQUE("date")
);
--> statement-breakpoint
CREATE TABLE "BusinessSettings" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"defaultTimezone" text DEFAULT 'Europe/Bucharest',
	"allowedTimezones" json NOT NULL,
	"businessHours" json NOT NULL,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "RateLimit" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"ip" text NOT NULL,
	"endpoint" text NOT NULL,
	"count" integer DEFAULT 1,
	"window" timestamp NOT NULL,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "RateLimit_ip_endpoint_window_key" UNIQUE("ip","endpoint","window")
);
--> statement-breakpoint
CREATE TABLE "account" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid NOT NULL,
	"accountId" text NOT NULL,
	"providerId" text NOT NULL,
	"accessToken" text,
	"refreshToken" text,
	"password" text,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "account_userId_providerId_key" UNIQUE("userId","providerId")
);
--> statement-breakpoint
CREATE TABLE "session" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid NOT NULL,
	"token" text NOT NULL,
	"expiresAt" timestamp NOT NULL,
	"ipAddress" text,
	"userAgent" text,
	"deviceId" uuid,
	"isActive" boolean DEFAULT true,
	"lastUsedAt" timestamp DEFAULT now() NOT NULL,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "session_token_key" UNIQUE("token")
);
--> statement-breakpoint
CREATE TABLE "twoFactor" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid NOT NULL,
	"type" "TwoFactorType" DEFAULT 'TOTP',
	"secret" text NOT NULL,
	"backupCodes" text[] DEFAULT '{}',
	"isActive" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	"lastUsedAt" timestamp,
	CONSTRAINT "twoFactor_userId_type_key" UNIQUE("userId","type")
);
--> statement-breakpoint
CREATE TABLE "user" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text,
	"email" text NOT NULL,
	"emailVerified" boolean DEFAULT false,
	"image" text,
	"role" "AdminRole" DEFAULT 'ADMIN',
	"timezone" text DEFAULT 'Europe/Bucharest',
	"preferences" json,
	"twoFactorEnabled" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	"lastLoginAt" timestamp,
	"lastLoginIp" text,
	CONSTRAINT "user_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "userAuditLog" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid NOT NULL,
	"action" "AuditAction" NOT NULL,
	"description" text NOT NULL,
	"ipAddress" text,
	"userAgent" text,
	"deviceId" uuid,
	"metadata" json,
	"success" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "userDevice" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid NOT NULL,
	"deviceName" text NOT NULL,
	"deviceType" "DeviceType" DEFAULT 'DESKTOP',
	"fingerprint" text NOT NULL,
	"isTrusted" boolean DEFAULT false,
	"lastUsedAt" timestamp DEFAULT now() NOT NULL,
	"ipAddress" text,
	"userAgent" text,
	"location" text,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "userDevice_fingerprint_key" UNIQUE("fingerprint")
);
--> statement-breakpoint
CREATE TABLE "verification" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"identifier" text NOT NULL,
	"value" text NOT NULL,
	"expiresAt" timestamp NOT NULL,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "verification_identifier_value_key" UNIQUE("identifier","value")
);
--> statement-breakpoint
CREATE TABLE "Campaign" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"type" text,
	"status" text DEFAULT 'DRAFT',
	"startDate" timestamp,
	"endDate" timestamp,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "CampaignSegment" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"campaignId" uuid NOT NULL,
	"segmentId" uuid NOT NULL,
	CONSTRAINT "CampaignSegment_campaignId_segmentId_key" UNIQUE("campaignId","segmentId")
);
--> statement-breakpoint
CREATE TABLE "ContactMessage" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"email" text NOT NULL,
	"phone" text,
	"serviceType" text,
	"message" text NOT NULL,
	"isRead" boolean DEFAULT false,
	"isArchived" boolean DEFAULT false,
	"consentGiven" boolean DEFAULT false,
	"retentionDate" timestamp,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "MarketingCampaign" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text NOT NULL,
	"segmentId" uuid,
	"subject" text NOT NULL,
	"content" text NOT NULL,
	"scheduledAt" timestamp,
	"sentAt" timestamp,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "Newsletter" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"email" text NOT NULL,
	"name" text,
	"isActive" boolean DEFAULT true,
	"source" text,
	"preferences" json,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "Newsletter_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "NewsletterSubscription" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"email" text NOT NULL,
	"status" text DEFAULT 'ACTIVE',
	"source" text,
	"unsubscribedAt" timestamp,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "NewsletterSubscription_email_key" UNIQUE("email")
);
--> statement-breakpoint
CREATE TABLE "Notification" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"title" text NOT NULL,
	"content" text NOT NULL,
	"type" text DEFAULT 'EMAIL',
	"status" text DEFAULT 'PENDING',
	"priority" text DEFAULT 'MEDIUM',
	"customerId" uuid,
	"adminId" uuid,
	"templateId" uuid,
	"scheduledAt" timestamp,
	"deliveredAt" timestamp,
	"readAt" timestamp,
	"error" text,
	"retryCount" json DEFAULT '0'::json,
	"maxRetries" json DEFAULT '3'::json,
	"metadata" json,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "NotificationTemplate" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"description" text,
	"key" text NOT NULL,
	"type" text DEFAULT 'EMAIL',
	"category" text,
	"subject" text,
	"content" text NOT NULL,
	"variables" json,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "NotificationTemplate_key_key" UNIQUE("key")
);
--> statement-breakpoint
CREATE TABLE "PushSubscription" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"endpoint" text NOT NULL,
	"p256dh" text NOT NULL,
	"auth" text NOT NULL,
	"userAgent" text,
	"email" text,
	"userId" uuid,
	"customerId" uuid,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "PushSubscription_endpoint_key" UNIQUE("endpoint")
);
--> statement-breakpoint
CREATE INDEX "CustomerLoyalty_tier_idx" ON "CustomerLoyalty" USING btree ("tier");--> statement-breakpoint
CREATE INDEX "CustomerLoyalty_points_idx" ON "CustomerLoyalty" USING btree ("points");--> statement-breakpoint
CREATE INDEX "CustomerLoyalty_lastActivityDate_idx" ON "CustomerLoyalty" USING btree ("lastActivityDate");--> statement-breakpoint
CREATE INDEX "CustomerOffer_loyaltyId_idx" ON "CustomerOffer" USING btree ("loyaltyId");--> statement-breakpoint
CREATE INDEX "CustomerOffer_offerType_idx" ON "CustomerOffer" USING btree ("offerType");--> statement-breakpoint
CREATE INDEX "CustomerOffer_validUntil_idx" ON "CustomerOffer" USING btree ("validUntil");--> statement-breakpoint
CREATE INDEX "CustomerOffer_isUsed_idx" ON "CustomerOffer" USING btree ("isUsed");--> statement-breakpoint
CREATE INDEX "CustomerSegment_isActive_idx" ON "CustomerSegment" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "CustomerSegmentMember_segmentId_idx" ON "CustomerSegmentMember" USING btree ("segmentId");--> statement-breakpoint
CREATE INDEX "CustomerSegmentMember_customerId_idx" ON "CustomerSegmentMember" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "Customer_email_idx" ON "Customer" USING btree ("email");--> statement-breakpoint
CREATE INDEX "Customer_phone_idx" ON "Customer" USING btree ("phone");--> statement-breakpoint
CREATE INDEX "Customer_birthday_idx" ON "Customer" USING btree ("birthday");--> statement-breakpoint
CREATE INDEX "Customer_marketingConsent_idx" ON "Customer" USING btree ("marketingConsent");--> statement-breakpoint
CREATE INDEX "Customer_totalReservations_idx" ON "Customer" USING btree ("totalReservations");--> statement-breakpoint
CREATE INDEX "Customer_lastReservationDate_idx" ON "Customer" USING btree ("lastReservationDate");--> statement-breakpoint
CREATE INDEX "Customer_marketingConsent_createdAt_idx" ON "Customer" USING btree ("marketingConsent","createdAt");--> statement-breakpoint
CREATE INDEX "Customer_preferredLanguage_createdAt_idx" ON "Customer" USING btree ("preferredLanguage","createdAt");--> statement-breakpoint
CREATE INDEX "DataConsent_email_idx" ON "DataConsent" USING btree ("email");--> statement-breakpoint
CREATE INDEX "DataConsent_consentType_idx" ON "DataConsent" USING btree ("consentType");--> statement-breakpoint
CREATE INDEX "DataConsent_createdAt_idx" ON "DataConsent" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "DataDeletionRequest_email_idx" ON "DataDeletionRequest" USING btree ("email");--> statement-breakpoint
CREATE INDEX "DataDeletionRequest_status_idx" ON "DataDeletionRequest" USING btree ("status");--> statement-breakpoint
CREATE INDEX "DataDeletionRequest_requestedAt_idx" ON "DataDeletionRequest" USING btree ("requestedAt");--> statement-breakpoint
CREATE INDEX "LoyaltyPointsHistory_loyaltyId_idx" ON "LoyaltyPointsHistory" USING btree ("loyaltyId");--> statement-breakpoint
CREATE INDEX "LoyaltyPointsHistory_createdAt_idx" ON "LoyaltyPointsHistory" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "LoyaltyPointsHistory_reservationId_idx" ON "LoyaltyPointsHistory" USING btree ("reservationId");--> statement-breakpoint
CREATE INDEX "PackagePurchase_customerId_idx" ON "PackagePurchase" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "PackagePurchase_packageId_idx" ON "PackagePurchase" USING btree ("packageId");--> statement-breakpoint
CREATE INDEX "PackagePurchase_isActive_idx" ON "PackagePurchase" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "PackagePurchase_expiresAt_idx" ON "PackagePurchase" USING btree ("expiresAt");--> statement-breakpoint
CREATE INDEX "Service_code_idx" ON "Service" USING btree ("code");--> statement-breakpoint
CREATE INDEX "Service_serviceType_idx" ON "Service" USING btree ("serviceType");--> statement-breakpoint
CREATE INDEX "Service_isActive_idx" ON "Service" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "Service_sortOrder_idx" ON "Service" USING btree ("sortOrder");--> statement-breakpoint
CREATE INDEX "ServicePackage_isActive_idx" ON "ServicePackage" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "ServicePackage_status_idx" ON "ServicePackage" USING btree ("status");--> statement-breakpoint
CREATE INDEX "ServicePackageItem_servicePackageId_idx" ON "ServicePackageItem" USING btree ("servicePackageId");--> statement-breakpoint
CREATE INDEX "ServicePackageItem_serviceId_idx" ON "ServicePackageItem" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "ServicePricing_serviceType_idx" ON "ServicePricing" USING btree ("serviceType");--> statement-breakpoint
CREATE INDEX "ServicePricing_isActive_idx" ON "ServicePricing" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "RecurringBooking_customerId_idx" ON "RecurringBooking" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "RecurringBooking_isActive_idx" ON "RecurringBooking" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "RecurringBooking_frequency_idx" ON "RecurringBooking" USING btree ("frequency");--> statement-breakpoint
CREATE INDEX "Reservation_date_idx" ON "Reservation" USING btree ("date");--> statement-breakpoint
CREATE INDEX "Reservation_status_idx" ON "Reservation" USING btree ("status");--> statement-breakpoint
CREATE INDEX "Reservation_customerEmail_idx" ON "Reservation" USING btree ("customerEmail");--> statement-breakpoint
CREATE INDEX "Reservation_customerId_idx" ON "Reservation" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "Reservation_serviceId_idx" ON "Reservation" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "Reservation_utcDateTime_idx" ON "Reservation" USING btree ("utcDateTime");--> statement-breakpoint
CREATE INDEX "Reservation_bookingType_idx" ON "Reservation" USING btree ("bookingType");--> statement-breakpoint
CREATE INDEX "Reservation_servicePackageId_idx" ON "Reservation" USING btree ("servicePackageId");--> statement-breakpoint
CREATE INDEX "Reservation_recurringBookingId_idx" ON "Reservation" USING btree ("recurringBookingId");--> statement-breakpoint
CREATE INDEX "WaitingList_customerId_idx" ON "WaitingList" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "WaitingList_preferredDate_idx" ON "WaitingList" USING btree ("preferredDate");--> statement-breakpoint
CREATE INDEX "WaitingList_isActive_idx" ON "WaitingList" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "WaitingList_priority_idx" ON "WaitingList" USING btree ("priority");--> statement-breakpoint
CREATE INDEX "Review_createdAt_idx" ON "Review" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "Review_serviceType_idx" ON "Review" USING btree ("serviceType");--> statement-breakpoint
CREATE INDEX "Review_status_idx" ON "Review" USING btree ("status");--> statement-breakpoint
CREATE INDEX "Review_isVisible_idx" ON "Review" USING btree ("isVisible");--> statement-breakpoint
CREATE INDEX "Review_customerEmail_idx" ON "Review" USING btree ("customerEmail");--> statement-breakpoint
CREATE INDEX "Admin_email_idx" ON "Admin" USING btree ("email");--> statement-breakpoint
CREATE INDEX "Admin_role_idx" ON "Admin" USING btree ("role");--> statement-breakpoint
CREATE INDEX "Admin_isActive_idx" ON "Admin" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "AuditLog_action_idx" ON "AuditLog" USING btree ("action");--> statement-breakpoint
CREATE INDEX "AuditLog_entityType_idx" ON "AuditLog" USING btree ("entityType");--> statement-breakpoint
CREATE INDEX "AuditLog_email_idx" ON "AuditLog" USING btree ("email");--> statement-breakpoint
CREATE INDEX "AuditLog_createdAt_idx" ON "AuditLog" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "BusinessMetrics_date_idx" ON "BusinessMetrics" USING btree ("date");--> statement-breakpoint
CREATE INDEX "RateLimit_window_idx" ON "RateLimit" USING btree ("window");--> statement-breakpoint
CREATE INDEX "session_userId_idx" ON "session" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "session_isActive_idx" ON "session" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "session_expiresAt_idx" ON "session" USING btree ("expiresAt");--> statement-breakpoint
CREATE INDEX "twoFactor_userId_idx" ON "twoFactor" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "twoFactor_isActive_idx" ON "twoFactor" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "user_email_idx" ON "user" USING btree ("email");--> statement-breakpoint
CREATE INDEX "userAuditLog_userId_idx" ON "userAuditLog" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "userAuditLog_action_idx" ON "userAuditLog" USING btree ("action");--> statement-breakpoint
CREATE INDEX "userAuditLog_createdAt_idx" ON "userAuditLog" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "userAuditLog_success_idx" ON "userAuditLog" USING btree ("success");--> statement-breakpoint
CREATE INDEX "userDevice_userId_idx" ON "userDevice" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "userDevice_fingerprint_idx" ON "userDevice" USING btree ("fingerprint");--> statement-breakpoint
CREATE INDEX "userDevice_isTrusted_idx" ON "userDevice" USING btree ("isTrusted");--> statement-breakpoint
CREATE INDEX "userDevice_lastUsedAt_idx" ON "userDevice" USING btree ("lastUsedAt");--> statement-breakpoint
CREATE INDEX "Campaign_status_idx" ON "Campaign" USING btree ("status");--> statement-breakpoint
CREATE INDEX "Campaign_createdAt_idx" ON "Campaign" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "CampaignSegment_campaignId_idx" ON "CampaignSegment" USING btree ("campaignId");--> statement-breakpoint
CREATE INDEX "CampaignSegment_segmentId_idx" ON "CampaignSegment" USING btree ("segmentId");--> statement-breakpoint
CREATE INDEX "ContactMessage_createdAt_idx" ON "ContactMessage" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "ContactMessage_isRead_idx" ON "ContactMessage" USING btree ("isRead");--> statement-breakpoint
CREATE INDEX "ContactMessage_email_idx" ON "ContactMessage" USING btree ("email");--> statement-breakpoint
CREATE INDEX "ContactMessage_retentionDate_idx" ON "ContactMessage" USING btree ("retentionDate");--> statement-breakpoint
CREATE INDEX "MarketingCampaign_segmentId_idx" ON "MarketingCampaign" USING btree ("segmentId");--> statement-breakpoint
CREATE INDEX "MarketingCampaign_scheduledAt_idx" ON "MarketingCampaign" USING btree ("scheduledAt");--> statement-breakpoint
CREATE INDEX "MarketingCampaign_isActive_idx" ON "MarketingCampaign" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "Newsletter_isActive_idx" ON "Newsletter" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "Newsletter_email_idx" ON "Newsletter" USING btree ("email");--> statement-breakpoint
CREATE INDEX "NewsletterSubscription_email_idx" ON "NewsletterSubscription" USING btree ("email");--> statement-breakpoint
CREATE INDEX "NewsletterSubscription_status_idx" ON "NewsletterSubscription" USING btree ("status");--> statement-breakpoint
CREATE INDEX "NewsletterSubscription_createdAt_idx" ON "NewsletterSubscription" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "Notification_customerId_idx" ON "Notification" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "Notification_adminId_idx" ON "Notification" USING btree ("adminId");--> statement-breakpoint
CREATE INDEX "Notification_status_idx" ON "Notification" USING btree ("status");--> statement-breakpoint
CREATE INDEX "Notification_type_idx" ON "Notification" USING btree ("type");--> statement-breakpoint
CREATE INDEX "Notification_priority_idx" ON "Notification" USING btree ("priority");--> statement-breakpoint
CREATE INDEX "Notification_scheduledAt_idx" ON "Notification" USING btree ("scheduledAt");--> statement-breakpoint
CREATE INDEX "Notification_createdAt_idx" ON "Notification" USING btree ("createdAt");--> statement-breakpoint
CREATE INDEX "NotificationTemplate_type_idx" ON "NotificationTemplate" USING btree ("type");--> statement-breakpoint
CREATE INDEX "NotificationTemplate_category_idx" ON "NotificationTemplate" USING btree ("category");--> statement-breakpoint
CREATE INDEX "NotificationTemplate_isActive_idx" ON "NotificationTemplate" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "NotificationTemplate_key_idx" ON "NotificationTemplate" USING btree ("key");--> statement-breakpoint
CREATE INDEX "PushSubscription_customerId_idx" ON "PushSubscription" USING btree ("customerId");--> statement-breakpoint
CREATE INDEX "PushSubscription_email_idx" ON "PushSubscription" USING btree ("email");--> statement-breakpoint
CREATE INDEX "PushSubscription_isActive_idx" ON "PushSubscription" USING btree ("isActive");