"""create_cloud_servers_table

Revision ID: 005
Revises: 004
Create Date: 2026-05-16 00:00:00.000000
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

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


def upgrade() -> None:
    op.create_table(
        "cloud_servers",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("server_type", sa.String(length=32), nullable=False, server_default="dcimcloud"),
        sa.Column("account_type", sa.String(length=16), nullable=False, server_default="admin"),
        sa.Column("hostname", sa.String(length=255), nullable=False),
        sa.Column("port", sa.Integer(), nullable=False, server_default="0"),
        sa.Column("secure", sa.Boolean(), nullable=False, server_default="1"),
        sa.Column("username", sa.String(length=100), nullable=False),
        sa.Column("password_encrypted", sa.Text(), nullable=False),
        sa.Column("user_prefix", sa.String(length=64), nullable=True),
        sa.Column("disabled", sa.Boolean(), nullable=False, server_default="0"),
        sa.Column("status", sa.String(length=16), nullable=False, server_default="unknown"),
        sa.Column("last_check_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("last_check_message", sa.String(length=500), nullable=True),
        sa.Column("remark", sa.Text(), nullable=True),
        sa.Column("sort_order", sa.Integer(), nullable=False, server_default="0"),
        sa.Column(
            "created_at",
            sa.DateTime(timezone=True),
            server_default=sa.func.now(),
            nullable=False,
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.func.now(),
            nullable=False,
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index("ix_cloud_servers_server_type", "cloud_servers", ["server_type"])
    op.create_index("ix_cloud_servers_status", "cloud_servers", ["status"])


def downgrade() -> None:
    op.drop_index("ix_cloud_servers_status", table_name="cloud_servers")
    op.drop_index("ix_cloud_servers_server_type", table_name="cloud_servers")
    op.drop_table("cloud_servers")
