"""added  2fa cols

Revision ID: 2b9b4af9a472
Revises: 3c014ba418e2
Create Date: 2025-05-10 17:50:56.786195

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '2b9b4af9a472'
down_revision: Union[str, None] = '3c014ba418e2'
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('companies', sa.Column('is_2FA_enabled', sa.Boolean(), nullable=True))
    op.add_column('users', sa.Column('is_2FA_enabled', sa.Boolean(), nullable=True))
    op.add_column('users', sa.Column('temp_2fa_secret', sa.String(length=100), nullable=True))
    op.add_column('users', sa.Column('secret_2fa', sa.String(length=100), nullable=True))

    op.execute('UPDATE companies SET "is_2FA_enabled" = false')
    op.execute('UPDATE users SET "is_2FA_enabled" = false')


    # Step 3: Alter columns to be NOT NULL
    op.alter_column('companies', 'is_2FA_enabled', nullable=False)
    op.alter_column('users', 'is_2FA_enabled', nullable=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('users', 'secret_2fa')
    op.drop_column('users', 'temp_2fa_secret')
    op.drop_column('users', 'is_2FA_enabled')
    op.drop_column('companies', 'is_2FA_enabled')
    # ### end Alembic commands ###
