"""add custom provider tables

Revision ID: 5105eceaf7cb
Revises: 13dcd54b4a4d
Create Date: 2026-03-31 23:09:10.169828

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "5105eceaf7cb"
down_revision: str | Sequence[str] | None = "13dcd54b4a4d"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "custom_provider",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("display_name", sa.String(length=128), nullable=False),
        sa.Column("api_format", sa.String(length=32), nullable=False),
        sa.Column("base_url", sa.Text(), nullable=False),
        sa.Column("api_key", sa.Text(), nullable=False),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_table(
        "custom_provider_model",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("provider_id", sa.Integer(), nullable=False),
        sa.Column("model_id", sa.String(length=128), nullable=False),
        sa.Column("display_name", sa.String(length=128), nullable=False),
        sa.Column("media_type", sa.String(length=16), nullable=False),
        sa.Column("is_default", sa.Boolean(), nullable=False),
        sa.Column("is_enabled", sa.Boolean(), nullable=False),
        sa.Column("price_unit", sa.String(length=16), nullable=True),
        sa.Column("price_input", sa.Float(), nullable=True),
        sa.Column("price_output", sa.Float(), nullable=True),
        sa.Column("currency", sa.String(length=8), nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("provider_id", "model_id", name="uq_custom_provider_model"),
    )
    with op.batch_alter_table("custom_provider_model", schema=None) as batch_op:
        batch_op.create_index("ix_custom_provider_model_provider_id", ["provider_id"], unique=False)

    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("custom_provider_model", schema=None) as batch_op:
        batch_op.drop_index("ix_custom_provider_model_provider_id")

    op.drop_table("custom_provider_model")
    op.drop_table("custom_provider")
    # ### end Alembic commands ###
