ALTER TABLE app.watchlist_items
    ADD COLUMN IF NOT EXISTS label TEXT NOT NULL DEFAULT 'general',
    ADD COLUMN IF NOT EXISTS priority TEXT NOT NULL DEFAULT 'medium',
    ADD COLUMN IF NOT EXISTS trigger_operator TEXT NOT NULL DEFAULT 'lte',
    ADD COLUMN IF NOT EXISTS trigger_price_psm DOUBLE PRECISION CHECK (trigger_price_psm >= 0),
    ADD COLUMN IF NOT EXISTS last_reviewed_at TIMESTAMPTZ;

CREATE TABLE IF NOT EXISTS app.watchlist_events (
    event_id BIGSERIAL PRIMARY KEY,
    watchlist_item_id BIGINT NOT NULL REFERENCES app.watchlist_items(watchlist_item_id) ON DELETE CASCADE,
    event_type TEXT NOT NULL,
    summary TEXT NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_watchlist_items_label
    ON app.watchlist_items(label);
CREATE INDEX IF NOT EXISTS idx_watchlist_items_priority
    ON app.watchlist_items(priority);
CREATE INDEX IF NOT EXISTS idx_watchlist_events_item_created
    ON app.watchlist_events(watchlist_item_id, created_at DESC);
