CREATE TABLE IF NOT EXISTS supply_intelligence_account_routing_states (
    account_id BIGINT PRIMARY KEY,
    platform TEXT NOT NULL,
    account_status TEXT NOT NULL,
    routing_enabled BOOLEAN NOT NULL DEFAULT TRUE,
    risk_score INTEGER NOT NULL DEFAULT 0,
    reason_code TEXT NOT NULL DEFAULT '',
    last_probe_at TIMESTAMPTZ NOT NULL,
    version BIGINT NOT NULL DEFAULT 1
);

CREATE TABLE IF NOT EXISTS supply_intelligence_package_change_events (
    event_id TEXT PRIMARY KEY,
    event_type TEXT NOT NULL,
    package_id BIGINT NOT NULL,
    account_id BIGINT NOT NULL DEFAULT 1,
    platform TEXT NOT NULL,
    model TEXT NOT NULL,
    occurred_at TIMESTAMPTZ NOT NULL,
    version BIGINT NOT NULL,
    ack_status TEXT NOT NULL DEFAULT 'pending',
    ack_consumer TEXT NOT NULL DEFAULT '',
    ack_detail TEXT NOT NULL DEFAULT '',
    ack_time TIMESTAMPTZ
);
