CREATE TABLE "inventory_conflicts" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"household_id" uuid NOT NULL,
	"inventory_item_id" uuid,
	"scan_job_id" uuid,
	"conflict_type" text NOT NULL,
	"source_a" text NOT NULL,
	"source_a_priority" integer DEFAULT 0 NOT NULL,
	"source_b" text NOT NULL,
	"source_b_priority" integer DEFAULT 0 NOT NULL,
	"payload_a" jsonb NOT NULL,
	"payload_b" jsonb NOT NULL,
	"proposed_resolution" jsonb,
	"status" text DEFAULT 'open' NOT NULL,
	"resolved_by_user_id" uuid,
	"resolution" jsonb,
	"model_version" text,
	"prompt_version" text,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"resolved_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "inventory_conflicts" ADD CONSTRAINT "inventory_conflicts_household_id_households_id_fk" FOREIGN KEY ("household_id") REFERENCES "public"."households"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "inventory_conflicts" ADD CONSTRAINT "inventory_conflicts_inventory_item_id_inventory_items_id_fk" FOREIGN KEY ("inventory_item_id") REFERENCES "public"."inventory_items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "inventory_conflicts" ADD CONSTRAINT "inventory_conflicts_resolved_by_user_id_users_id_fk" FOREIGN KEY ("resolved_by_user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "inventory_conflicts_household_idx" ON "inventory_conflicts" USING btree ("household_id");--> statement-breakpoint
CREATE INDEX "inventory_conflicts_item_idx" ON "inventory_conflicts" USING btree ("inventory_item_id");--> statement-breakpoint
CREATE INDEX "inventory_conflicts_status_idx" ON "inventory_conflicts" USING btree ("status");