"""
Add actors table for actor registry.

Revision ID: c3d9b3d0cf3e
Revises: 4b518923afb2
Create Date: 2025-12-17 00:00:00

"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "c3d9b3d0cf3e"
down_revision: str | Sequence[str] | None = "4b518923afb2"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Create actors table."""

    op.create_table(
        "actors",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("name", sa.String(length=255), nullable=False),
        sa.Column("provider", sa.String(length=255), nullable=False),
        sa.Column("model", sa.String(length=255), nullable=False),
        sa.Column(
            "config_blob",
            sa.JSON(),
            nullable=False,
            server_default=sa.text("'{}'"),
        ),
        sa.Column("config_hash", sa.String(length=128), nullable=False),
        sa.Column("graph_descriptor", sa.JSON(), nullable=True),
        sa.Column(
            "unsafe",
            sa.Boolean(),
            nullable=False,
            server_default=sa.text("0"),
        ),
        sa.Column(
            "is_built_in",
            sa.Boolean(),
            nullable=False,
            server_default=sa.text("0"),
        ),
        sa.Column(
            "is_default",
            sa.Boolean(),
            nullable=False,
            server_default=sa.text("0"),
        ),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("name"),
    )
    op.create_index(
        op.f("ix_actors_is_default"), "actors", ["is_default"], unique=False
    )


def downgrade() -> None:
    """Drop actors table."""

    op.drop_index(op.f("ix_actors_is_default"), table_name="actors")
    op.drop_table("actors")
