"""add_more_fields

Revision ID: 0f106fabd22f
Revises: 4bcb140de81f
Create Date: 2024-11-23 10:33:27.024696

"""

from typing import Sequence
from typing import Union

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects.postgresql import ENUM

# revision identifiers, used by Alembic.
revision: str = "0f106fabd22f"
down_revision: Union[str, None] = "4bcb140de81f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # create enum type
    # Create the enum type
    interval_type_enum = ENUM(
        "MIN_1",
        "MIN_3",
        "MIN_5",
        "MIN_15",
        "MIN_30",
        "HOUR_1",
        "HOUR_2",
        "HOUR_4",
        "HOUR_6",
        "HOUR_8",
        "HOUR_12",
        "DAY_1",
        "DAY_7",
        "DAY_14",
        "WEEK_1",
        "MONTH_1",
        name="interval_type_enum",
    )
    interval_type_enum.create(op.get_bind())  # type: ignore

    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "xarizmi_candlestick", sa.Column("close", sa.Integer(), nullable=False)
    )
    op.add_column(
        "xarizmi_candlestick", sa.Column("open", sa.Integer(), nullable=False)
    )
    op.add_column(
        "xarizmi_candlestick", sa.Column("high", sa.Integer(), nullable=False)
    )
    op.add_column(
        "xarizmi_candlestick", sa.Column("low", sa.Integer(), nullable=False)
    )
    op.add_column(
        "xarizmi_candlestick",
        sa.Column("volume", sa.Integer(), nullable=False),
    )
    op.add_column(
        "xarizmi_candlestick", sa.Column("amount", sa.Integer(), nullable=True)
    )
    op.add_column(
        "xarizmi_candlestick",
        sa.Column("interval_type", interval_type_enum, nullable=False),
    )
    op.add_column(
        "xarizmi_candlestick",
        sa.Column("interval", sa.BigInteger(), nullable=True),
    )
    op.add_column(
        "xarizmi_candlestick",
        sa.Column("datetime", sa.DateTime(), nullable=False),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column("xarizmi_candlestick", "datetime")
    op.drop_column("xarizmi_candlestick", "interval")
    op.drop_column("xarizmi_candlestick", "interval_type")
    op.drop_column("xarizmi_candlestick", "amount")
    op.drop_column("xarizmi_candlestick", "volume")
    op.drop_column("xarizmi_candlestick", "low")
    op.drop_column("xarizmi_candlestick", "high")
    op.drop_column("xarizmi_candlestick", "open")
    op.drop_column("xarizmi_candlestick", "close")
    # ### end Alembic commands ###

    # Drop the enum type
    interval_type_enum = ENUM(
        "MIN_1",
        "MIN_3",
        "MIN_5",
        "MIN_15",
        "MIN_30",
        "HOUR_1",
        "HOUR_2",
        "HOUR_4",
        "HOUR_6",
        "HOUR_8",
        "HOUR_12",
        "DAY_1",
        "DAY_7",
        "DAY_14",
        "WEEK_1",
        "MONTH_1",
        name="interval_type_enum",
    )
    interval_type_enum.drop(op.get_bind())  # type: ignore
