CREATE TYPE banner_level AS ENUM ('info', 'important', 'critical');

CREATE TABLE IF NOT EXISTS announcement_banners (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  message TEXT NOT NULL,
  level banner_level NOT NULL DEFAULT 'info',
  starts_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  ends_at TIMESTAMPTZ,
  created_by UUID REFERENCES users(id) ON DELETE SET NULL,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_banners_active ON announcement_banners (starts_at, ends_at)
  WHERE ends_at IS NULL OR ends_at > NOW();
