CREATE TYPE "public"."CustomFieldType" AS ENUM('TEXT', 'NUMBER', 'BOOLEAN', 'JSON');--> statement-breakpoint
CREATE TYPE "public"."StaffRole" AS ENUM('TECHNICIAN', 'SPECIALIST', 'MANAGER');--> statement-breakpoint
CREATE TABLE "ServiceBlockedDate" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serviceId" uuid,
	"date" date NOT NULL,
	"reason" text,
	"isRecurring" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "ServiceCustomField" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serviceId" uuid NOT NULL,
	"fieldKey" text NOT NULL,
	"fieldType" "CustomFieldType" NOT NULL,
	"fieldValue" text,
	"labelRo" text,
	"labelEn" text,
	"sortOrder" integer DEFAULT 0,
	"isPublic" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "ServiceCustomField_serviceId_fieldKey_key" UNIQUE("serviceId","fieldKey")
);
--> statement-breakpoint
CREATE TABLE "ServiceSchedule" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serviceId" uuid NOT NULL,
	"dayOfWeek" integer NOT NULL,
	"startTime" text NOT NULL,
	"endTime" text NOT NULL,
	"maxBookings" integer,
	"isActive" boolean DEFAULT true,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "ServiceSchedule_serviceId_dayOfWeek_key" UNIQUE("serviceId","dayOfWeek")
);
--> statement-breakpoint
CREATE TABLE "ServiceStaff" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"serviceId" uuid NOT NULL,
	"staffId" uuid NOT NULL,
	"isPrimary" boolean DEFAULT false,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "ServiceStaff_serviceId_staffId_key" UNIQUE("serviceId","staffId")
);
--> statement-breakpoint
CREATE TABLE "Staff" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"name" text NOT NULL,
	"email" text,
	"phone" text,
	"role" "StaffRole" DEFAULT 'TECHNICIAN',
	"color" text DEFAULT '#3b82f6',
	"isActive" boolean DEFAULT true,
	"userId" uuid,
	"metadata" json,
	"createdAt" timestamp DEFAULT now() NOT NULL,
	"updatedAt" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "Staff_email_key" UNIQUE("email")
);
--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "category" text;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "minCapacity" integer DEFAULT 1;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "maxCapacity" integer DEFAULT 1;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "picture" text;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "defaultStatus" "ReservationStatus" DEFAULT 'PENDING';--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "minTimeBeforeBooking" integer DEFAULT 60;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "minTimeBeforeCancel" integer DEFAULT 1440;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "minTimeBeforeReschedule" integer DEFAULT 1440;--> statement-breakpoint
ALTER TABLE "Service" ADD COLUMN "webVisible" boolean DEFAULT true;--> statement-breakpoint
ALTER TABLE "ServiceBlockedDate" ADD CONSTRAINT "ServiceBlockedDate_serviceId_Service_id_fk" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ServiceCustomField" ADD CONSTRAINT "ServiceCustomField_serviceId_Service_id_fk" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ServiceSchedule" ADD CONSTRAINT "ServiceSchedule_serviceId_Service_id_fk" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ServiceStaff" ADD CONSTRAINT "ServiceStaff_serviceId_Service_id_fk" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ServiceStaff" ADD CONSTRAINT "ServiceStaff_staffId_Staff_id_fk" FOREIGN KEY ("staffId") REFERENCES "public"."Staff"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "Staff" ADD CONSTRAINT "Staff_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "ServiceBlockedDate_serviceId_idx" ON "ServiceBlockedDate" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "ServiceBlockedDate_date_idx" ON "ServiceBlockedDate" USING btree ("date");--> statement-breakpoint
CREATE INDEX "ServiceBlockedDate_isRecurring_idx" ON "ServiceBlockedDate" USING btree ("isRecurring");--> statement-breakpoint
CREATE INDEX "ServiceCustomField_serviceId_idx" ON "ServiceCustomField" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "ServiceCustomField_fieldKey_idx" ON "ServiceCustomField" USING btree ("fieldKey");--> statement-breakpoint
CREATE INDEX "ServiceCustomField_isPublic_idx" ON "ServiceCustomField" USING btree ("isPublic");--> statement-breakpoint
CREATE INDEX "ServiceSchedule_serviceId_idx" ON "ServiceSchedule" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "ServiceSchedule_dayOfWeek_idx" ON "ServiceSchedule" USING btree ("dayOfWeek");--> statement-breakpoint
CREATE INDEX "ServiceSchedule_isActive_idx" ON "ServiceSchedule" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "ServiceStaff_serviceId_idx" ON "ServiceStaff" USING btree ("serviceId");--> statement-breakpoint
CREATE INDEX "ServiceStaff_staffId_idx" ON "ServiceStaff" USING btree ("staffId");--> statement-breakpoint
CREATE INDEX "Staff_email_idx" ON "Staff" USING btree ("email");--> statement-breakpoint
CREATE INDEX "Staff_isActive_idx" ON "Staff" USING btree ("isActive");--> statement-breakpoint
CREATE INDEX "Staff_role_idx" ON "Staff" USING btree ("role");--> statement-breakpoint
CREATE INDEX "Staff_userId_idx" ON "Staff" USING btree ("userId");--> statement-breakpoint
CREATE INDEX "Service_category_idx" ON "Service" USING btree ("category");--> statement-breakpoint
CREATE INDEX "Service_webVisible_idx" ON "Service" USING btree ("webVisible");