-- Media Center
--
-- Extends actuate_media with the metadata the Media Center needs: SEO fields
-- (caption / description / focusKeyword), provenance (originalFileName), a
-- normalised storage split (publicUrl / storageProvider), media processing
-- artefacts (thumbnailUrl / responsiveVariants / durationSeconds), a tags
-- bag, soft-delete (deletedAt), and a processing status.
--
-- SEO score and issues are deliberately NOT persisted — they are derived on
-- read by `calculateMediaSeoScore()` so they never drift from the metadata.
--
-- Safe to apply to a populated database:
--   * Every new column is nullable or has a default — no backfill required.
--   * `status` defaults to READY so existing rows are immediately valid.
--   * No existing column is dropped or retyped.

-- ---------------------------------------------------------------------------
-- MediaStatus enum
-- ---------------------------------------------------------------------------
CREATE TYPE "MediaStatus" AS ENUM (
  'PROCESSING',
  'READY',
  'FAILED'
);

-- ---------------------------------------------------------------------------
-- actuate_media new columns
-- ---------------------------------------------------------------------------
ALTER TABLE "actuate_media"
  ADD COLUMN "originalFileName"   TEXT,
  ADD COLUMN "caption"            TEXT,
  ADD COLUMN "description"        TEXT,
  ADD COLUMN "focusKeyword"       TEXT,
  ADD COLUMN "tags"               JSONB,
  ADD COLUMN "publicUrl"          TEXT,
  ADD COLUMN "storageProvider"    TEXT,
  ADD COLUMN "durationSeconds"    DOUBLE PRECISION,
  ADD COLUMN "thumbnailUrl"       TEXT,
  ADD COLUMN "responsiveVariants" JSONB,
  ADD COLUMN "status"             "MediaStatus" NOT NULL DEFAULT 'READY',
  ADD COLUMN "deletedAt"          TIMESTAMP(3);

-- ---------------------------------------------------------------------------
-- Indexes backing the new query filters (soft-delete + type filtering)
-- ---------------------------------------------------------------------------
CREATE INDEX "actuate_media_deletedAt_idx" ON "actuate_media" ("deletedAt");
CREATE INDEX "actuate_media_mimeType_idx" ON "actuate_media" ("mimeType");
