-- Asset comments — frame-anchored notes on the Asset Detail page.
--
-- Comments are scoped to an asset and optionally to a timecode within that
-- asset. `frame_ms` is the playhead position when the comment was posted.
-- `resolved` lets editors hide rolled-up notes once addressed.
--
-- User ID is optional (nullable) so comments still attach when AUTH_ENABLED
-- is off and there's no real session user.

CREATE TABLE IF NOT EXISTS asset_comments (
  id          UUID        PRIMARY KEY DEFAULT gen_random_uuid(),
  asset_id    UUID        NOT NULL REFERENCES assets(id) ON DELETE CASCADE,
  user_id     UUID        REFERENCES users(id) ON DELETE SET NULL,
  body        TEXT        NOT NULL,
  frame_ms    INTEGER,
  resolved    BOOLEAN     NOT NULL DEFAULT FALSE,
  created_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at  TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_asset_comments_asset
  ON asset_comments (asset_id, created_at);
