"""Add appeal fields to organization_review

Revision ID: b5ffc01faa80
Revises: a1b2c3d4e5f6
Create Date: 2025-08-28 09:10:57.559307

"""

import sqlalchemy as sa
from alembic import op

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "b5ffc01faa80"
down_revision = "a1b2c3d4e5f6"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "organization_reviews",
        sa.Column("appeal_submitted_at", sa.TIMESTAMP(timezone=True), nullable=True),
    )
    op.add_column(
        "organization_reviews", sa.Column("appeal_reason", sa.Text(), nullable=True)
    )
    op.add_column(
        "organization_reviews",
        sa.Column("appeal_reviewed_at", sa.TIMESTAMP(timezone=True), nullable=True),
    )
    op.add_column(
        "organization_reviews", sa.Column("appeal_decision", sa.String(), nullable=True)
    )
    op.execute(
        "UPDATE organization_reviews SET appeal_decision = 'approved', appeal_reviewed_at = NOW() WHERE verdict = 'FAIL'"
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("organization_reviews", "appeal_decision")
    op.drop_column("organization_reviews", "appeal_reviewed_at")
    op.drop_column("organization_reviews", "appeal_reason")
    op.drop_column("organization_reviews", "appeal_submitted_at")
    # ### end Alembic commands ###
