CREATE TYPE "public"."ai_decision" AS ENUM('PASS', 'FLAG', 'REJECT', 'ERROR');--> statement-breakpoint
CREATE TYPE "public"."image_entity_type" AS ENUM('vendor', 'deal', 'user', 'page_module', 'support_ticket');--> statement-breakpoint
CREATE TYPE "public"."notification_severity" AS ENUM('info', 'warning', 'error');--> statement-breakpoint
CREATE TYPE "public"."upload_purpose" AS ENUM('deal_image', 'vendor_logo', 'vendor_hero', 'vendor_gallery', 'user_gallery', 'avatar', 'homepage_banner', 'support_attachment');--> statement-breakpoint
ALTER TYPE "public"."admin_target_type" ADD VALUE IF NOT EXISTS 'IMAGE';--> statement-breakpoint
CREATE TABLE "notifications" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"recipient_type" text NOT NULL,
	"recipient_id" uuid NOT NULL,
	"event_type" text NOT NULL,
	"severity" "notification_severity" DEFAULT 'warning' NOT NULL,
	"payload" jsonb NOT NULL,
	"read_at" timestamp with time zone,
	"resolved_at" timestamp with time zone,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "purpose" "upload_purpose";--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "entity_type" "image_entity_type";--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "entity_id" uuid;--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_decision" "ai_decision";--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_reason" text;--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_score" numeric(3, 2);--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_model" text;--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_checked_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "image_uploads" ADD COLUMN "ai_raw_payload" jsonb;--> statement-breakpoint
ALTER TABLE "user_gallery_images" ADD COLUMN "approval_status" "image_approval_status" DEFAULT 'APPROVED' NOT NULL;--> statement-breakpoint
ALTER TABLE "user_gallery_images" ADD COLUMN "reject_reason_code" text;--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "avatar_approval_status" "image_approval_status" DEFAULT 'APPROVED' NOT NULL;--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "pending_avatar_value" text;--> statement-breakpoint
ALTER TABLE "users" ADD COLUMN "avatar_reject_reason_code" text;--> statement-breakpoint
ALTER TABLE "vendor_gallery_images" ADD COLUMN "approval_status" "image_approval_status" DEFAULT 'APPROVED' NOT NULL;--> statement-breakpoint
ALTER TABLE "vendor_gallery_images" ADD COLUMN "reject_reason_code" text;--> statement-breakpoint
ALTER TABLE "vendors" ADD COLUMN "logo_approval_status" "image_approval_status" DEFAULT 'APPROVED' NOT NULL;--> statement-breakpoint
ALTER TABLE "vendors" ADD COLUMN "pending_logo_url" text;--> statement-breakpoint
ALTER TABLE "vendors" ADD COLUMN "pending_logo_r2_key" text;--> statement-breakpoint
ALTER TABLE "vendors" ADD COLUMN "logo_reject_reason_code" text;--> statement-breakpoint
CREATE INDEX "notifications_unresolved_idx" ON "notifications" USING btree ("recipient_type","recipient_id") WHERE "notifications"."resolved_at" IS NULL;--> statement-breakpoint
CREATE INDEX "image_uploads_entity_idx" ON "image_uploads" USING btree ("entity_type","entity_id");--> statement-breakpoint
CREATE INDEX "image_uploads_purpose_idx" ON "image_uploads" USING btree ("purpose");
