"""Attention, replacing confidence as what a person reads on a row.

Confidence answers "how sure is the machine". Attention answers "how much of your judgement does
this need", and they are different axes: a 99%-sure merge that sets a precedent for every set that
follows deserves more of a person than a 60%-sure attribute on one variant nobody else stocks.
Rian, 18 Sep, naming the five levels: critical, high, medium, low, none.

`confidence` is kept. It is what a pass measured, it is part of the proposals file, and the
spot-check rule reads it. Attention is what the page shows.

Revision ID: c2d3e4f5a6b7
Revises: e3f4a5b6c7d8
"""
from alembic import op
import sqlalchemy as sa

revision = "c2d3e4f5a6b7"
down_revision = "e3f4a5b6c7d8"
branch_labels = None
depends_on = None

LEVELS = ("critical", "high", "medium", "low", "none")


def upgrade() -> None:
    op.add_column("proposals", sa.Column("attention", sa.String(10), nullable=True))
    op.create_check_constraint(
        "ck_proposals_attention",
        "proposals",
        "attention IS NULL OR attention IN ('critical', 'high', 'medium', 'low', 'none')",
    )
    op.create_index("ix_proposals_attention", "proposals", ["brand_slug", "attention"],
                    postgresql_where=sa.text("status = 'open'"))


def downgrade() -> None:
    op.drop_index("ix_proposals_attention", table_name="proposals")
    op.drop_constraint("ck_proposals_attention", "proposals", type_="check")
    op.drop_column("proposals", "attention")
