CREATE TYPE "public"."admin_moderation_type" AS ENUM('corrected', 'marked_incorrect');--> statement-breakpoint
CREATE TYPE "public"."reason_code" AS ENUM('wrong_object', 'wrong_category', 'false_positive', 'unclear_image', 'duplicate', 'out_of_scope');--> statement-breakpoint
CREATE TABLE "admin_moderation" (
	"id" text PRIMARY KEY NOT NULL,
	"detection_id" text NOT NULL,
	"admin_id" text NOT NULL,
	"action" "admin_moderation_type" NOT NULL,
	"reason_code" "reason_code",
	"original_values" jsonb NOT NULL,
	"corrected_values" jsonb,
	"train_ai_flag" boolean DEFAULT true NOT NULL,
	"created_at" timestamp (3) with time zone DEFAULT now() NOT NULL,
	"updated_at" timestamp (3) with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "admin_moderation" ADD CONSTRAINT "admin_moderation_detection_id_detected_objects_id_fk" FOREIGN KEY ("detection_id") REFERENCES "public"."detected_objects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "admin_moderation" ADD CONSTRAINT "admin_moderation_admin_id_users_id_fk" FOREIGN KEY ("admin_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_admin_moderation_detection_id" ON "admin_moderation" ("detection_id");--> statement-breakpoint
CREATE INDEX "idx_admin_moderation_admin_id" ON "admin_moderation" ("admin_id");--> statement-breakpoint
CREATE INDEX "idx_admin_moderation_created_at" ON "admin_moderation" ("created_at");