"""user mobile fields for unified SSO

Revision ID: 0002_user_mobile
Revises: 0001_initial
Create Date: 2026-07-07
"""
from __future__ import annotations

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0002_user_mobile"
down_revision: Union[str, None] = "0001_initial"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("user_profiles", sa.Column("mobile", sa.String(length=15), nullable=True))
    op.add_column(
        "user_profiles",
        sa.Column("mobile_verified", sa.Boolean(), nullable=False, server_default=sa.text("false")),
    )
    op.add_column(
        "user_profiles",
        sa.Column("mobile_verified_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.add_column("user_profiles", sa.Column("core_user_id", sa.UUID(), nullable=True))
    op.create_index("ix_user_profiles_mobile", "user_profiles", ["mobile"], unique=True)
    op.alter_column("user_profiles", "mobile_verified", server_default=None)


def downgrade() -> None:
    op.drop_index("ix_user_profiles_mobile", table_name="user_profiles")
    op.drop_column("user_profiles", "core_user_id")
    op.drop_column("user_profiles", "mobile_verified_at")
    op.drop_column("user_profiles", "mobile_verified")
    op.drop_column("user_profiles", "mobile")
