"""Recovery codes and totp

Revision ID: a585fd97b88c
Revises: a8e40ab24138
Create Date: 2026-01-18 15:09:58.721180

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision: str = "a585fd97b88c"
down_revision: Union[str, None] = "a8e40ab24138"
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.add_column("users", sa.Column("is_2fa_enabled", sa.Boolean(), nullable=False))
    op.add_column(
        "users",
        sa.Column(
            "totp_secret", sqlmodel.sql.sqltypes.AutoString(length=80), nullable=True
        ),
    )
    op.add_column(
        "users",
        sa.Column(
            "recovery_code_hashes",
            sqlmodel.sql.sqltypes.AutoString(length=1500),
            nullable=True,
        ),
    )
    op.add_column(
        "users", sa.Column("recovery_codes_generated_at", sa.DateTime(), nullable=True)
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("users", "recovery_codes_generated_at")
    op.drop_column("users", "recovery_code_hashes")
    op.drop_column("users", "totp_secret")
    op.drop_column("users", "is_2fa_enabled")
    # ### end Alembic commands ###
