"""add_language_settings_to_vendor_user_customer

Revision ID: fcfdc02d5138
Revises: b412e0b49c2e
Create Date: 2025-12-13 20:08:27.120863

This migration adds language preference fields to support multi-language UI:
- Vendor: default_language, dashboard_language, storefront_language
- User: preferred_language
- Customer: preferred_language

Supported languages: en (English), fr (French), de (German), lb (Luxembourgish)
"""
from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "fcfdc02d5138"
down_revision: str | None = "b412e0b49c2e"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    # ========================================================================
    # Vendor language settings
    # ========================================================================
    # default_language: Default language for vendor content (products, etc.)
    op.add_column(
        "vendors",
        sa.Column("default_language", sa.String(5), nullable=False, server_default="fr")
    )
    # dashboard_language: Language for vendor team dashboard UI
    op.add_column(
        "vendors",
        sa.Column("dashboard_language", sa.String(5), nullable=False, server_default="fr")
    )
    # storefront_language: Default language for customer-facing shop
    op.add_column(
        "vendors",
        sa.Column("storefront_language", sa.String(5), nullable=False, server_default="fr")
    )
    # storefront_languages: JSON array of enabled languages for storefront
    # Allows vendors to enable/disable specific languages
    op.add_column(
        "vendors",
        sa.Column(
            "storefront_languages",
            sa.JSON,
            nullable=False,
            server_default='["fr", "de", "en"]'
        )
    )

    # ========================================================================
    # User language preference
    # ========================================================================
    # preferred_language: User's preferred UI language (NULL = use context default)
    op.add_column(
        "users",
        sa.Column("preferred_language", sa.String(5), nullable=True)
    )

    # ========================================================================
    # Customer language preference
    # ========================================================================
    # preferred_language: Customer's preferred language (NULL = use storefront default)
    op.add_column(
        "customers",
        sa.Column("preferred_language", sa.String(5), nullable=True)
    )


def downgrade() -> None:
    # Remove columns in reverse order
    op.drop_column("customers", "preferred_language")
    op.drop_column("users", "preferred_language")
    op.drop_column("vendors", "storefront_languages")
    op.drop_column("vendors", "storefront_language")
    op.drop_column("vendors", "dashboard_language")
    op.drop_column("vendors", "default_language")
