"""review_status enum on rfp_document_question

Revision ID: 37444aa582fe
Revises: 0dfb0cdf94bf
Create Date: 2026-03-05 02:33:03.081469

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '37444aa582fe'
down_revision: Union[str, Sequence[str], None] = '0dfb0cdf94bf'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('rfp_document_question', sa.Column('review_status', sa.Enum('PENDING', 'ACCEPTED', 'NEEDS_REVISION', name='reviewstatus', native_enum=False), nullable=True))
    op.execute(
        """
        UPDATE rfp_document_question
        SET review_status = 'PENDING'
        WHERE review_status IS NULL
        """
    )
    op.add_column('rfp_document_question', sa.Column('reviewed_at', sa.DateTime(timezone=True), nullable=True))
    op.add_column('rfp_document_question', sa.Column('reviewed_by_contact_id', sa.Integer(), nullable=True))
    op.create_index(op.f('rfp_document_question_review_status_idx'), 'rfp_document_question', ['review_status'], unique=False)
    op.create_index(op.f('rfp_document_question_reviewed_by_contact_id_idx'), 'rfp_document_question', ['reviewed_by_contact_id'], unique=False)
    op.create_foreign_key(op.f('rfp_document_question_reviewed_by_contact_id_fkey'), 'rfp_document_question', 'contact', ['reviewed_by_contact_id'], ['id'], ondelete='SET NULL')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f('rfp_document_question_reviewed_by_contact_id_fkey'), 'rfp_document_question', type_='foreignkey')
    op.drop_index(op.f('rfp_document_question_reviewed_by_contact_id_idx'), table_name='rfp_document_question')
    op.drop_index(op.f('rfp_document_question_review_status_idx'), table_name='rfp_document_question')
    op.drop_column('rfp_document_question', 'reviewed_by_contact_id')
    op.drop_column('rfp_document_question', 'reviewed_at')
    op.drop_column('rfp_document_question', 'review_status')
    # ### end Alembic commands ###
