"""Add red_review, blue_review states and review-assignment columns to tests.

Revision ID: b057
Revises: b056
Create Date: 2026-07-06
"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = "b057"
down_revision = "b056"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("ALTER TYPE teststate ADD VALUE IF NOT EXISTS 'red_review'")
    op.execute("ALTER TYPE teststate ADD VALUE IF NOT EXISTS 'blue_review'")

    op.add_column("tests", sa.Column("red_reviewer_assignee", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True))
    op.add_column("tests", sa.Column("red_review_by", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True))
    op.add_column("tests", sa.Column("red_review_at", sa.DateTime(), nullable=True))
    op.add_column("tests", sa.Column("red_review_notes", sa.Text(), nullable=True))
    op.add_column("tests", sa.Column("blue_reviewer_assignee", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True))
    op.add_column("tests", sa.Column("blue_review_by", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id"), nullable=True))
    op.add_column("tests", sa.Column("blue_review_at", sa.DateTime(), nullable=True))
    op.add_column("tests", sa.Column("blue_review_notes", sa.Text(), nullable=True))
    op.add_column("tests", sa.Column("system_gaps", sa.Text(), nullable=True))


def downgrade() -> None:
    op.drop_column("tests", "system_gaps")
    op.drop_column("tests", "blue_review_notes")
    op.drop_column("tests", "blue_review_at")
    op.drop_column("tests", "blue_review_by")
    op.drop_column("tests", "blue_reviewer_assignee")
    op.drop_column("tests", "red_review_notes")
    op.drop_column("tests", "red_review_at")
    op.drop_column("tests", "red_review_by")
    op.drop_column("tests", "red_reviewer_assignee")
    # PostgreSQL does not support removing enum values; downgrade is a no-op
    # for the enum part, matching b046_add_disputed_test_state.py.
