"""v0.12.2 migration

Revision ID: bd59252fe91f
Revises: f2395550aab9
Create Date: 2025-06-08 21:49:56.254908

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision: str = "bd59252fe91f"
down_revision: Union[str, None] = "f2395550aab9"
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.alter_column(
        "gear",
        "gear_type",
        existing_type=sa.INTEGER(),
        comment="Gear type (1 - bike, 2 - shoes, 3 - wetsuit, 4 - racquet, 5 - skis, 6 - snowboard)",
        existing_comment="Gear type (1 - bike, 2 - shoes, 3 - wetsuit, 4 - racquet)",
        existing_nullable=False,
    )
    op.add_column(
        "users_default_gear",
        sa.Column(
            "alpine_ski_gear_id",
            sa.Integer(),
            nullable=True,
            comment="Gear ID that the default alpine ski activity type belongs",
        ),
    )
    op.add_column(
        "users_default_gear",
        sa.Column(
            "nordic_ski_gear_id",
            sa.Integer(),
            nullable=True,
            comment="Gear ID that the default nordic ski activity type belongs",
        ),
    )
    op.add_column(
        "users_default_gear",
        sa.Column(
            "snowboard_gear_id",
            sa.Integer(),
            nullable=True,
            comment="Gear ID that the default snowboard activity type belongs",
        ),
    )
    op.create_index(
        op.f("ix_users_default_gear_alpine_ski_gear_id"),
        "users_default_gear",
        ["alpine_ski_gear_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_users_default_gear_nordic_ski_gear_id"),
        "users_default_gear",
        ["nordic_ski_gear_id"],
        unique=False,
    )
    op.create_index(
        op.f("ix_users_default_gear_snowboard_gear_id"),
        "users_default_gear",
        ["snowboard_gear_id"],
        unique=False,
    )
    op.create_foreign_key(
        "fk_users_default_gear_alpine_ski_gear_id",
        "users_default_gear",
        "gear",
        ["alpine_ski_gear_id"],
        ["id"],
        ondelete="SET NULL",
    )
    op.create_foreign_key(
        "fk_users_default_gear_nordic_ski_gear_id",
        "users_default_gear",
        "gear",
        ["nordic_ski_gear_id"],
        ["id"],
        ondelete="SET NULL",
    )
    op.create_foreign_key(
        "fk_users_default_gear_snowboard_gear_id",
        "users_default_gear",
        "gear",
        ["snowboard_gear_id"],
        ["id"],
        ondelete="SET NULL",
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("fk_users_default_gear_snowboard_gear_id", "users_default_gear", type_="foreignkey")
    op.drop_constraint("fk_users_default_gear_nordic_ski_gear_id", "users_default_gear", type_="foreignkey")
    op.drop_constraint("fk_users_default_gear_alpine_ski_gear_id", "users_default_gear", type_="foreignkey")
    op.drop_index(
        op.f("ix_users_default_gear_snowboard_gear_id"), table_name="users_default_gear"
    )
    op.drop_index(
        op.f("ix_users_default_gear_nordic_ski_gear_id"), table_name="users_default_gear"
    )
    op.drop_index(
        op.f("ix_users_default_gear_alpine_ski_gear_id"), table_name="users_default_gear"
    )
    op.drop_column("users_default_gear", "snowboard_gear_id")
    op.drop_column("users_default_gear", "nordic_ski_gear_id")
    op.drop_column("users_default_gear", "alpine_ski_gear_id")
    op.alter_column(
        "gear",
        "gear_type",
        existing_type=sa.INTEGER(),
        comment="Gear type (1 - bike, 2 - shoes, 3 - wetsuit, 4 - racquet)",
        existing_comment="Gear type (1 - bike, 2 - shoes, 3 - wetsuit, 4 - racquet, 5 - skis, 6 - snowboard)",
        existing_nullable=False,
    )
    # ### end Alembic commands ###
