"""Initial schema baseline

Revision ID: f2a7eb2d7c36
Revises:
Create Date: 2025-08-24 15:47:50.256152

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "f2a7eb2d7c36"
down_revision: Union[str, Sequence[str], None] = None
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.create_table(
        "players",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("player_name", sa.String(length=80), nullable=True),
        sa.Column("xuid", sa.String(length=20), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_players_id"), "players", ["id"], unique=False)
    op.create_index(
        op.f("ix_players_player_name"), "players", ["player_name"], unique=True
    )
    op.create_index(op.f("ix_players_xuid"), "players", ["xuid"], unique=True)
    op.create_table(
        "plugins",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("plugin_name", sa.String(length=255), nullable=True),
        sa.Column("config", sa.JSON(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_plugins_id"), "plugins", ["id"], unique=False)
    op.create_index(
        op.f("ix_plugins_plugin_name"), "plugins", ["plugin_name"], unique=True
    )
    op.create_table(
        "registration_tokens",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("token", sa.String(length=255), nullable=True),
        sa.Column("role", sa.String(length=50), nullable=True),
        sa.Column("expires", sa.Integer(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_registration_tokens_id"), "registration_tokens", ["id"], unique=False
    )
    op.create_index(
        op.f("ix_registration_tokens_token"),
        "registration_tokens",
        ["token"],
        unique=True,
    )
    op.create_table(
        "servers",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("server_name", sa.String(length=255), nullable=True),
        sa.Column("config", sa.JSON(), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_servers_id"), "servers", ["id"], unique=False)
    op.create_index(
        op.f("ix_servers_server_name"), "servers", ["server_name"], unique=True
    )
    op.create_table(
        "users",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("username", sa.String(length=80), nullable=True),
        sa.Column("hashed_password", sa.String(length=255), nullable=True),
        sa.Column("role", sa.String(length=50), nullable=True),
        sa.Column("last_seen", sa.DateTime(), nullable=True),
        sa.Column("theme", sa.String(length=50), nullable=True),
        sa.Column("is_active", sa.Boolean(), nullable=True),
        sa.Column("full_name", sa.String(length=255), nullable=True),
        sa.Column("email", sa.String(length=255), nullable=True),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_users_id"), "users", ["id"], unique=False)
    op.create_index(op.f("ix_users_username"), "users", ["username"], unique=True)
    op.create_table(
        "audit_logs",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("timestamp", sa.DateTime(), nullable=True),
        sa.Column("user_id", sa.Integer(), nullable=True),
        sa.Column("action", sa.String(length=255), nullable=True),
        sa.Column("details", sa.JSON(), nullable=True),
        sa.ForeignKeyConstraint(
            ["user_id"],
            ["users.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_audit_logs_id"), "audit_logs", ["id"], unique=False)
    op.create_table(
        "settings",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("key", sa.String(length=255), nullable=True),
        sa.Column("value", sa.JSON(), nullable=True),
        sa.Column("server_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["server_id"],
            ["servers.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_settings_id"), "settings", ["id"], unique=False)
    op.create_index(op.f("ix_settings_key"), "settings", ["key"], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f("ix_settings_key"), table_name="settings")
    op.drop_index(op.f("ix_settings_id"), table_name="settings")
    op.drop_table("settings")
    op.drop_index(op.f("ix_audit_logs_id"), table_name="audit_logs")
    op.drop_table("audit_logs")
    op.drop_index(op.f("ix_users_username"), table_name="users")
    op.drop_index(op.f("ix_users_id"), table_name="users")
    op.drop_table("users")
    op.drop_index(op.f("ix_servers_server_name"), table_name="servers")
    op.drop_index(op.f("ix_servers_id"), table_name="servers")
    op.drop_table("servers")
    op.drop_index(
        op.f("ix_registration_tokens_token"), table_name="registration_tokens"
    )
    op.drop_index(op.f("ix_registration_tokens_id"), table_name="registration_tokens")
    op.drop_table("registration_tokens")
    op.drop_index(op.f("ix_plugins_plugin_name"), table_name="plugins")
    op.drop_index(op.f("ix_plugins_id"), table_name="plugins")
    op.drop_table("plugins")
    op.drop_index(op.f("ix_players_xuid"), table_name="players")
    op.drop_index(op.f("ix_players_player_name"), table_name="players")
    op.drop_index(op.f("ix_players_id"), table_name="players")
    op.drop_table("players")
    # ### end Alembic commands ###
