"""add conversation_custom_question table

Revision ID: a7b8c9d0e1f2
Revises: f6a7b8c9d0e1
Create Date: 2026-07-25
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = 'a7b8c9d0e1f2'
down_revision = 'f6a7b8c9d0e1'
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        'conversation_custom_question',
        sa.Column('id', postgresql.UUID(as_uuid=True), primary_key=True),
        sa.Column('session_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('intake_session.id', ondelete='CASCADE'), nullable=False),
        sa.Column('department_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('mstr_department.id'), nullable=False),
        sa.Column('utterance_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('conversation_utterance.id', ondelete='CASCADE'), nullable=False),
        sa.Column('question_text', sa.Text(), nullable=False),
        sa.Column('review_status', sa.String(length=20), nullable=False, server_default='PENDING'),
        sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.func.now(), nullable=False),
    )
    op.create_index(
        'conversation_custom_question_dept_idx',
        'conversation_custom_question',
        ['department_id', 'created_at'],
    )


def downgrade() -> None:
    op.drop_index('conversation_custom_question_dept_idx', table_name='conversation_custom_question')
    op.drop_table('conversation_custom_question')
