"""add_domain_term_dictionary

Revision ID: 6302e01e470e
Revises: 04571689d204
Create Date: 2026-01-15 11:26:04.000000

"""
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 = '6302e01e470e'
down_revision: Union[str, None] = '04571689d204'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Create domain_term_dictionary table
    op.create_table('domain_term_dictionary',
        sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('term_original', sa.String(length=255), nullable=False),
        sa.Column('term_ja', sa.String(length=255), nullable=True),
        sa.Column('term_en', sa.String(length=255), nullable=True),
        sa.Column('term_vi', sa.String(length=255), nullable=True),
        sa.Column('source_language', sa.String(length=10), nullable=False),
        sa.Column('domain_category', sa.String(length=100), server_default='general', nullable=False),
        sa.Column('source_document_id', postgresql.UUID(as_uuid=True), nullable=True),
        sa.Column('translation_failed', sa.Boolean(), server_default='false', nullable=False),
        sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('term_original')
    )

    # Create indexes
    op.create_index('idx_domain_dict_term_ja', 'domain_term_dictionary', ['term_ja'], unique=False)
    op.create_index('idx_domain_dict_term_en', 'domain_term_dictionary', ['term_en'], unique=False)
    op.create_index('idx_domain_dict_term_vi', 'domain_term_dictionary', ['term_vi'], unique=False)


def downgrade() -> None:
    # Drop indexes (if_exists to handle partial rollback scenarios)
    op.drop_index('idx_domain_dict_term_vi', table_name='domain_term_dictionary', if_exists=True)
    op.drop_index('idx_domain_dict_term_en', table_name='domain_term_dictionary', if_exists=True)
    op.drop_index('idx_domain_dict_term_ja', table_name='domain_term_dictionary', if_exists=True)

    # Drop table (if_exists to handle partial rollback scenarios)
    op.drop_table('domain_term_dictionary', if_exists=True)
