CREATE TABLE "vendor_recommendations" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"vendor_id" uuid NOT NULL,
	"kind" text NOT NULL,
	"payload" jsonb NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	"dismissed_at" timestamp with time zone
);
--> statement-breakpoint
ALTER TABLE "vendor_recommendations" ADD CONSTRAINT "vendor_recommendations_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "vendor_recommendations_vendor_created_idx" ON "vendor_recommendations" USING btree ("vendor_id","created_at");
--> statement-breakpoint
-- ─── Seed 9 customer route page layouts (P0 gap-closure) ─────────────────────
-- Inserts a version-1 layout + live pointer for each route.
-- Uses DO $$ to skip routes that already have a pointer (idempotent).
-- stub_body shape matches LayoutModule: {instanceId, type, config, visibility}
-- static-content config shape: {body: {he, en}, background}
DO $$
DECLARE
  v_id uuid;
  stub_body jsonb := '[{"instanceId":"stub-static","type":"static-content","config":{"body":{"he":"תוכן זמני — יעודכן בשלב P2","en":"Placeholder — authored in P2"},"background":"neutral"},"visibility":{"guests":true,"loggedIn":true}}]'::jsonb;
  stub_layout_body jsonb := jsonb_build_object('mobile', stub_body, 'desktop', stub_body);
  routes text[] := ARRAY['about','faq','contact','favorites','wishlist','stores','loyalty','category'];
  r text;
BEGIN
  -- home: skip if pointer already exists
  IF NOT EXISTS (SELECT 1 FROM page_layout_pointers WHERE page = 'home') THEN
    INSERT INTO page_layouts (id, page, version, body, note)
      VALUES (gen_random_uuid(), 'home', 1, stub_layout_body, 'P0 seed')
      RETURNING id INTO v_id;
    INSERT INTO page_layout_pointers (page, live_version_id)
      VALUES ('home', v_id);
  END IF;

  -- remaining 8 routes
  FOREACH r IN ARRAY routes LOOP
    IF NOT EXISTS (SELECT 1 FROM page_layout_pointers WHERE page = r) THEN
      INSERT INTO page_layouts (id, page, version, body, note)
        VALUES (gen_random_uuid(), r, 1, stub_layout_body, 'P0 seed')
        RETURNING id INTO v_id;
      INSERT INTO page_layout_pointers (page, live_version_id)
        VALUES (r, v_id);
    END IF;
  END LOOP;
END $$;
