"""add organization_review

Revision ID: 098b3c536fec
Revises: 393cb2f82868
Create Date: 2025-08-08 12:12:21.421527

"""

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

# Polar Custom Imports

# revision identifiers, used by Alembic.
revision = "098b3c536fec"
down_revision = "393cb2f82868"
branch_labels: tuple[str] | None = None
depends_on: tuple[str] | None = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "organization_reviews",
        sa.Column("organization_id", sa.Uuid(), nullable=False),
        sa.Column("verdict", sa.String(), nullable=False),
        sa.Column("risk_score", sa.Float(), nullable=False),
        sa.Column(
            "violated_sections", postgresql.JSONB(astext_type=sa.Text()), nullable=False
        ),
        sa.Column("reason", sa.Text(), nullable=False),
        sa.Column("timed_out", sa.Boolean(), nullable=False),
        sa.Column("model_used", sa.String(), nullable=False),
        sa.Column(
            "organization_details_snapshot",
            postgresql.JSONB(astext_type=sa.Text()),
            nullable=False,
        ),
        sa.Column("validated_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("id", sa.Uuid(), nullable=False),
        sa.Column("created_at", sa.TIMESTAMP(timezone=True), nullable=False),
        sa.Column("modified_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.Column("deleted_at", sa.TIMESTAMP(timezone=True), nullable=True),
        sa.ForeignKeyConstraint(
            ["organization_id"],
            ["organizations.id"],
            name=op.f("organization_reviews_organization_id_fkey"),
            ondelete="cascade",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("organization_reviews_pkey")),
    )
    op.create_index(
        op.f("ix_organization_reviews_created_at"),
        "organization_reviews",
        ["created_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_organization_reviews_deleted_at"),
        "organization_reviews",
        ["deleted_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_organization_reviews_modified_at"),
        "organization_reviews",
        ["modified_at"],
        unique=False,
    )
    op.create_index(
        op.f("ix_organization_reviews_organization_id"),
        "organization_reviews",
        ["organization_id"],
        unique=True,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(
        op.f("ix_organization_reviews_organization_id"),
        table_name="organization_reviews",
    )
    op.drop_index(
        op.f("ix_organization_reviews_modified_at"), table_name="organization_reviews"
    )
    op.drop_index(
        op.f("ix_organization_reviews_deleted_at"), table_name="organization_reviews"
    )
    op.drop_index(
        op.f("ix_organization_reviews_created_at"), table_name="organization_reviews"
    )
    op.drop_table("organization_reviews")
    # ### end Alembic commands ###
