"""feat: add user extra data

Revision ID: bd9e7152958f
Revises: 4650a36b9e03
Create Date: 2025-02-28 07:52:17.649263

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = "bd9e7152958f"
down_revision = "4650a36b9e03"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "script_ui_profile_id",
                sa.String(length=36),
                nullable=True,
                comment="Script UI profile id",
            )
        )
        batch_op.create_index(
            batch_op.f("ix_ai_lesson_script_script_ui_profile_id"),
            ["script_ui_profile_id"],
            unique=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column("profile_prompt_type", sa.Integer(), nullable=False)
        )
        batch_op.add_column(
            sa.Column(
                "profile_prompt", sa.Text(), nullable=False, comment="Profile prompt"
            )
        )
        batch_op.add_column(
            sa.Column(
                "profile_prompt_model",
                sa.Text(),
                nullable=False,
                comment="Profile prompt model",
            )
        )
        batch_op.add_column(
            sa.Column(
                "profile_prompt_model_args",
                sa.Text(),
                nullable=False,
                comment="Profile prompt model args",
            )
        )
        batch_op.add_column(
            sa.Column(
                "profile_script_id",
                sa.String(length=36),
                nullable=False,
                comment="Profile script id",
            )
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_check_model",
            existing_type=mysql.VARCHAR(length=255),
            comment="",
            existing_nullable=False,
        )
        batch_op.create_index(
            batch_op.f("ix_profile_item_profile_script_id"),
            ["profile_script_id"],
            unique=False,
        )

    with op.batch_alter_table("profile_item_i18n", schema=None) as batch_op:
        batch_op.alter_column(
            "conf_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column("extra_data", sa.Text(), nullable=True, comment="extra_data")
        )

    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment="",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_profile", schema=None) as batch_op:
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
            existing_server_default=sa.text("'0'"),
        )

    with op.batch_alter_table("user_info", schema=None) as batch_op:
        batch_op.drop_column("extra_data")

    with op.batch_alter_table("profile_item_i18n", schema=None) as batch_op:
        batch_op.alter_column(
            "conf_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )

    with op.batch_alter_table("profile_item", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_profile_item_profile_script_id"))
        batch_op.alter_column(
            "profile_check_model",
            existing_type=mysql.VARCHAR(length=255),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_show_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_value_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.alter_column(
            "profile_type",
            existing_type=mysql.INTEGER(display_width=11),
            comment=None,
            existing_comment="",
            existing_nullable=False,
        )
        batch_op.drop_column("profile_script_id")
        batch_op.drop_column("profile_prompt_model_args")
        batch_op.drop_column("profile_prompt_model")
        batch_op.drop_column("profile_prompt")
        batch_op.drop_column("profile_prompt_type")

    with op.batch_alter_table("ai_lesson_script", schema=None) as batch_op:
        batch_op.drop_index(batch_op.f("ix_ai_lesson_script_script_ui_profile_id"))
        batch_op.drop_column("script_ui_profile_id")

    # ### end Alembic commands ###
