"""add_order_model

Revision ID: 40610635cc37
Revises: e33464855650
Create Date: 2025-04-08 18:17:09.117814

"""

from typing import Sequence
from typing import Union

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

# revision identifiers, used by Alembic.
revision: str = "40610635cc37"
down_revision: Union[str, None] = "e33464855650"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "xarizmi_order",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("symbol_id", sa.Integer(), nullable=False),
        sa.Column("order_id", sa.String(), nullable=False),
        sa.Column("amount", sa.Float(), nullable=False),
        sa.Column("price", sa.Float(), nullable=False),
        sa.Column(
            "side", sa.Enum("BUY", "SELL", name="side_enum"), nullable=False
        ),
        sa.Column(
            "status",
            sa.Enum(
                "ACTIVE",
                "DONE",
                "PARTIALLY_FILLED",
                "CANCELLED",
                name="order_status_enum",
            ),
            nullable=False,
        ),
        sa.ForeignKeyConstraint(
            ["symbol_id"],
            ["xarizmi_symbol.id"],
        ),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint(
            "symbol_id", "order_id", name="uix_symbol_id_order_id"
        ),
    )
    op.alter_column(
        "xarizmi_candlestick",
        "interval_type",
        existing_type=postgresql.INTERVAL(),
        type_=sa.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",
        ),
        existing_nullable=False,
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "xarizmi_candlestick",
        "interval_type",
        existing_type=sa.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",
        ),
        type_=postgresql.INTERVAL(),
        existing_nullable=False,
    )
    op.drop_table("xarizmi_order")
    # ### end Alembic commands ###
