"""user SSO link and mobile verification fields

Revision ID: 0004_user_sso_link
Revises: 0003_platform_admin
Create Date: 2026-07-07
"""
from __future__ import annotations

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "0004_user_sso_link"
down_revision: Union[str, None] = "0003_platform_admin"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("users", sa.Column("keycloak_sub", sa.String(length=100), nullable=True))
    op.add_column("users", sa.Column("email", sa.String(length=255), nullable=True))
    op.add_column(
        "users",
        sa.Column("mobile_verified", sa.Boolean(), nullable=False, server_default=sa.text("true")),
    )
    op.create_index("ix_users_keycloak_sub", "users", ["keycloak_sub"], unique=True)
    op.alter_column("users", "mobile_verified", server_default=None)


def downgrade() -> None:
    op.drop_index("ix_users_keycloak_sub", table_name="users")
    op.drop_column("users", "mobile_verified")
    op.drop_column("users", "email")
    op.drop_column("users", "keycloak_sub")
