"""add intelligent eval tables

Revision ID: 99dbae2a20da
Revises: c5d8f0a2e4b7
Create Date: 2026-08-05 02:52:58.120905

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel


# revision identifiers, used by Alembic.
revision: str = '99dbae2a20da'
down_revision: Union[str, Sequence[str], None] = 'c5d8f0a2e4b7'
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.create_table('intelligent_evals',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('target_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('goal', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('seeds', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('intent', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('role_description', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('plan', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('plan_feedback', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('time_window_hours', sa.Integer(), nullable=False),
    sa.Column('report', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('started_at', sa.DateTime(), nullable=True),
    sa.Column('completed_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['target_id'], ['eval_targets.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('intelligent_eval_sessions',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('eval_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('target_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('persona', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('goal', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('dimension', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('status', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('verdict', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('turn_count', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('closed_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['eval_id'], ['intelligent_evals.id'], ),
    sa.ForeignKeyConstraint(['target_id'], ['eval_targets.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('intelligent_eval_sessions', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_intelligent_eval_sessions_eval_id'), ['eval_id'], unique=False)

    op.create_table('intelligent_eval_messages',
    sa.Column('id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('session_id', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('role', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('content', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('latency_ms', sa.Integer(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.ForeignKeyConstraint(['session_id'], ['intelligent_eval_sessions.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    with op.batch_alter_table('intelligent_eval_messages', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_intelligent_eval_messages_session_id'), ['session_id'], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('intelligent_eval_messages', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_intelligent_eval_messages_session_id'))

    op.drop_table('intelligent_eval_messages')
    with op.batch_alter_table('intelligent_eval_sessions', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_intelligent_eval_sessions_eval_id'))

    op.drop_table('intelligent_eval_sessions')
    op.drop_table('intelligent_evals')
    # ### end Alembic commands ###
