-- Performance indexes — round 2.
-- Covers query shapes added to the company/place detail page AFTER the first
-- perf pass (recent-activity ticker, AI review summary). Idempotent
-- (IF NOT EXISTS), additive only — no schema/model changes. Apply via the
-- same `prisma db execute` flow as scripts/sql/perf-indexes.sql.

-- 1. getCompanyRecentActivity → Review branch. Filters
--    (companyId, status) with a createdAt >= since range, ordered by
--    createdAt DESC. Also covers getCompanyReviewSummary's
--    (companyId, status) filter. The schema already has
--    @@index([companyId, status]); appending createdAt DESC makes the
--    ordered range scan index-only and avoids a sort.
CREATE INDEX IF NOT EXISTS "review_company_status_created_idx"
  ON "Review" ("companyId", "status", "createdAt" DESC);

-- 2. getCompanyRecentActivity → Booking branch. Filters
--    (companyId, bookingStatus) with an updatedAt >= since range, ordered
--    by updatedAt DESC. Schema only has @@index([companyId, status])
--    (legacy free-form status) and @@index([bookingStatus, startAt]) —
--    none lead with (companyId, bookingStatus) for this query shape.
CREATE INDEX IF NOT EXISTS "booking_company_bookingstatus_updated_idx"
  ON "Booking" ("companyId", "bookingStatus", "updatedAt" DESC);

-- NOTE: RecentlyViewed (visitorAccountId|sessionId, viewedAt) lookups are
-- already covered by existing @@index entries in the Prisma schema — no
-- extra index needed there.
