"""Add user_knockout_guess table and remove hardcoded knockout columns

Revision ID: 488d33a92340
Revises: d1ca70b9e5e1
Create Date: 2026-03-04 15:55:54.099845

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "488d33a92340"
down_revision = "d1ca70b9e5e1"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "user_knockout_guess",
        sa.Column("id", sa.UUID(), nullable=False),
        sa.Column("user_id", sa.UUID(), nullable=False),
        sa.Column("group_id", sa.UUID(), nullable=False),
        sa.Column("count", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(["group_id"], ["group.id"]),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("user_id", "group_id", name="uq_user_knockout_guess"),
    )
    op.drop_column("user", "number_semi_final_guess")
    op.drop_column("user", "number_quarter_final_guess")
    op.drop_column("user", "number_final_guess")
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "user", sa.Column("number_final_guess", sa.INTEGER(), autoincrement=False, nullable=False)
    )
    op.add_column(
        "user",
        sa.Column("number_quarter_final_guess", sa.INTEGER(), autoincrement=False, nullable=False),
    )
    op.add_column(
        "user",
        sa.Column("number_semi_final_guess", sa.INTEGER(), autoincrement=False, nullable=False),
    )
    op.drop_table("user_knockout_guess")
    # ### end Alembic commands ###
