-- =============================================================================
-- Per-user queue preferences
-- =============================================================================
-- Lets each user hide specific queues from their own dashboard widgets
-- (notably the Queue posture heatmap). Presence of a row = that user has
-- hidden that queue. Absence = visible.
--
-- Independent of the global company_scope filter — that affects KPI counts
-- for everyone, this only affects what an individual user chooses to see.
-- =============================================================================

CREATE TABLE IF NOT EXISTS user_queue_preferences (
  user_id    TEXT        NOT NULL REFERENCES "user"(id) ON DELETE CASCADE,
  queue_id   INTEGER     NOT NULL REFERENCES queues(value) ON DELETE CASCADE,
  hidden_at  TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  PRIMARY KEY (user_id, queue_id)
);

CREATE INDEX IF NOT EXISTS idx_user_queue_preferences_user
  ON user_queue_preferences(user_id);

COMMENT ON TABLE user_queue_preferences IS
  'Per-user hidden-queue list. Row presence = queue is hidden for that user in dashboard widgets.';
