"""Refactor feedback analysis for unified event log

Revision ID: 5a52fb845dc0
Revises: 24b3f480777b
Create Date: 2025-11-21 18:01:46.770048

"""
from typing import Sequence, Union

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

# revision identifiers, used by Alembic.
revision: str = '5a52fb845dc0'
down_revision: Union[str, Sequence[str], None] = '24b3f480777b'
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('feedback_analysis', sa.Column('agent_message', sa.JSON(), nullable=True))
    op.add_column('feedback_analysis', sa.Column('user_response', sa.JSON(), nullable=True))
    op.drop_column('feedback_analysis', 'reason_to_reject')
    op.drop_column('feedback_analysis', 'analysis_type')
    op.drop_column('feedback_analysis', 'created_chunks')
    op.drop_column('feedback_analysis', 'retrieved_chunks')
    op.add_column('feedback_chunk_update', sa.Column('action_rationale', sa.Text(), nullable=True))
    op.alter_column('feedback_chunk_update', 'status',
               existing_type=sa.VARCHAR(length=50),
               nullable=True)
    # op.drop_column('source', 'sync_enabled')
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    # op.add_column('source', sa.Column('sync_enabled', sa.BOOLEAN(), autoincrement=False, nullable=True))
    op.alter_column('feedback_chunk_update', 'status',
               existing_type=sa.VARCHAR(length=50),
               nullable=False)
    op.drop_column('feedback_chunk_update', 'action_rationale')
    op.add_column('feedback_analysis', sa.Column('retrieved_chunks', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=True))
    op.add_column('feedback_analysis', sa.Column('created_chunks', postgresql.ARRAY(sa.INTEGER()), autoincrement=False, nullable=True))
    op.add_column('feedback_analysis', sa.Column('analysis_type', sa.VARCHAR(length=50), autoincrement=False, nullable=True))
    op.add_column('feedback_analysis', sa.Column('reason_to_reject', sa.TEXT(), autoincrement=False, nullable=True))
    op.drop_column('feedback_analysis', 'user_response')
    op.drop_column('feedback_analysis', 'agent_message')
    # ### end Alembic commands ###
