"""post-text translation via Interpreter (milestone 143) — Post columns + settings

Post gains the translated title/description + the detected source language,
Interpreter engine_version (cache key), and translated_at — filled by the
translate sweep. ImportSettings gains translation_enabled (OFF by default),
interpreter_base_url (EMPTY — the operator sets their own, behind a reverse
proxy), and translation_target_lang (en).

Revision ID: 0083
Revises: 0082
Create Date: 2026-07-07
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0083"
down_revision: Union[str, None] = "0082"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column(
        "post", sa.Column("post_title_translated", sa.Text(), nullable=True)
    )
    op.add_column(
        "post", sa.Column("description_translated", sa.Text(), nullable=True)
    )
    op.add_column(
        "post",
        sa.Column("translated_source_lang", sa.String(8), nullable=True),
    )
    op.add_column(
        "post",
        sa.Column("translation_engine_version", sa.String(128), nullable=True),
    )
    op.add_column(
        "post",
        sa.Column("translated_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.add_column(
        "import_settings",
        sa.Column(
            "translation_enabled", sa.Boolean(), nullable=False,
            server_default=sa.text("false"),
        ),
    )
    op.add_column(
        "import_settings",
        sa.Column(
            "interpreter_base_url", sa.Text(), nullable=False, server_default="",
        ),
    )
    op.add_column(
        "import_settings",
        sa.Column(
            "translation_target_lang", sa.Text(), nullable=False,
            server_default="en",
        ),
    )


def downgrade() -> None:
    op.drop_column("import_settings", "translation_target_lang")
    op.drop_column("import_settings", "interpreter_base_url")
    op.drop_column("import_settings", "translation_enabled")
    op.drop_column("post", "translated_at")
    op.drop_column("post", "translation_engine_version")
    op.drop_column("post", "translated_source_lang")
    op.drop_column("post", "description_translated")
    op.drop_column("post", "post_title_translated")
