"""Add user status

Revision ID: 99379162619e
Revises: bc48af5ec2e6
Create Date: 2022-09-11 17:20:02.341713

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy import orm

# revision identifiers, used by Alembic.
revision = "99379162619e"
down_revision = "f7e0e62a5cfa"
branch_labels = None
depends_on = None

Base = orm.declarative_base()


class User(Base):
    __tablename__ = "users"
    id = sa.Column(sa.Integer, primary_key=True)
    is_deleted = sa.Column(sa.Boolean, nullable=False, default=False)
    is_banned = sa.Column(sa.Boolean, nullable=False, default=False)
    is_verified = sa.Column(sa.Boolean, nullable=False, default=False)


def upgrade() -> None:
    op.add_column("users", sa.Column("is_deleted", sa.Boolean, nullable=True))
    op.add_column("users", sa.Column("is_banned", sa.Boolean, nullable=True))
    op.add_column("users", sa.Column("is_verified", sa.Boolean, nullable=True))

    bind = op.get_bind()
    session = orm.Session(bind=bind)
    for user in session.query(User).all():
        user.is_deleted = False
        user.is_banned = False
        user.is_verified = False
        session.add(user)
    session.commit()

    with op.batch_alter_table("users") as batch_op:
        batch_op.alter_column("is_deleted", existing_type=sa.BOOLEAN(), nullable=False)
        batch_op.alter_column("is_banned", existing_type=sa.BOOLEAN(), nullable=False)
        batch_op.alter_column("is_verified", existing_type=sa.BOOLEAN(), nullable=False)


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("users", "is_deleted")
    op.drop_column("users", "is_banned")
    op.drop_column("users", "is_verified")
    # ### end Alembic commands ###
