"""add_i18n_support

Revision ID: 1a9ae6818aaf
Revises: 45c563ec8ff5
Create Date: 2026-11-18 05:23:50.366608

"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '1a9ae6818aaf'
down_revision: Union[str, None] = '45c563ec8ff5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tenant_locales',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('tenant_id', sa.UUID(), nullable=False),
    sa.Column('locale', sa.String(length=10), nullable=False),
    sa.Column('is_enabled', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('tenant_id', 'locale', name='uq_tenant_locale')
    )
    op.create_index(op.f('ix_tenant_locales_tenant_id'), 'tenant_locales', ['tenant_id'], unique=False)
    op.create_table('translations',
    sa.Column('id', sa.UUID(), nullable=False),
    sa.Column('tenant_id', sa.UUID(), nullable=True),
    sa.Column('locale', sa.String(length=10), nullable=False),
    sa.Column('namespace', sa.String(length=50), nullable=False),
    sa.Column('key', sa.String(length=100), nullable=False),
    sa.Column('value', sa.Text(), nullable=False),
    sa.Column('is_approved', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
    sa.ForeignKeyConstraint(['tenant_id'], ['tenants.id'], ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_translations_key'), 'translations', ['key'], unique=False)
    op.create_index(op.f('ix_translations_locale'), 'translations', ['locale'], unique=False)
    op.create_index('ix_translations_lookup', 'translations', ['tenant_id', 'locale', 'namespace', 'key'], unique=False)
    op.create_index(op.f('ix_translations_namespace'), 'translations', ['namespace'], unique=False)
    op.create_index(op.f('ix_translations_tenant_id'), 'translations', ['tenant_id'], unique=False)
    op.add_column('bot_users', sa.Column('preferred_locale', sa.String(length=10), server_default='en', nullable=False))
    op.add_column('bots', sa.Column('default_locale', sa.String(length=10), server_default='en', nullable=False))
    op.add_column('tenants', sa.Column('default_locale', sa.String(length=10), server_default='en', nullable=False))
    op.add_column('users', sa.Column('preferred_locale', sa.String(length=10), server_default='en', nullable=False))
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'preferred_locale')
    op.drop_column('tenants', 'default_locale')
    op.drop_column('bots', 'default_locale')
    op.drop_column('bot_users', 'preferred_locale')
    op.drop_index(op.f('ix_translations_tenant_id'), table_name='translations')
    op.drop_index(op.f('ix_translations_namespace'), table_name='translations')
    op.drop_index('ix_translations_lookup', table_name='translations')
    op.drop_index(op.f('ix_translations_locale'), table_name='translations')
    op.drop_index(op.f('ix_translations_key'), table_name='translations')
    op.drop_table('translations')
    op.drop_index(op.f('ix_tenant_locales_tenant_id'), table_name='tenant_locales')
    op.drop_table('tenant_locales')
    # ### end Alembic commands ###
