"""add users oem_id and agent_id

Revision ID: 006
Revises: 005
Create Date: 2026-05-21

"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "006"
down_revision: Union[str, None] = "005"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.add_column("users", sa.Column("oem_id", sa.Integer(), nullable=True))
    op.add_column("users", sa.Column("agent_id", sa.Integer(), nullable=True))
    op.create_foreign_key(
        "fk_users_oem_id_users",
        "users",
        "users",
        ["oem_id"],
        ["id"],
        ondelete="SET NULL",
    )
    op.create_foreign_key(
        "fk_users_agent_id_users",
        "users",
        "users",
        ["agent_id"],
        ["id"],
        ondelete="SET NULL",
    )
    op.create_index("ix_users_oem_id", "users", ["oem_id"])
    op.create_index("ix_users_agent_id", "users", ["agent_id"])


def downgrade() -> None:
    op.drop_index("ix_users_agent_id", table_name="users")
    op.drop_index("ix_users_oem_id", table_name="users")
    op.drop_constraint("fk_users_agent_id_users", "users", type_="foreignkey")
    op.drop_constraint("fk_users_oem_id_users", "users", type_="foreignkey")
    op.drop_column("users", "agent_id")
    op.drop_column("users", "oem_id")
