"""create cart_items table

Revision ID: 015_cart_items
Revises: 014_product_groups_parent_id
Create Date: 2026-05-17
"""

from alembic import op
import sqlalchemy as sa

revision = "015_cart_items"
down_revision = "014_product_groups_parent_id"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "cart_items",
        sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.Column("user_id", sa.BigInteger(), sa.ForeignKey("users.id", ondelete="CASCADE"), nullable=False),
        sa.Column("product_id", sa.Integer(), sa.ForeignKey("products.id", ondelete="CASCADE"), nullable=False),
        sa.Column("cycle", sa.String(16), nullable=False),
        sa.Column("quantity", sa.Integer(), nullable=False, server_default="1"),
        sa.Column("auto_renew", sa.Boolean(), nullable=False, server_default=sa.false()),
        sa.Column("alias", sa.String(64), nullable=True),
        sa.Column("os_image", sa.String(128), nullable=True),
        sa.Column("unit_price", sa.Numeric(10, 2), nullable=False),
        sa.Column("addon_price", sa.Numeric(10, 2), nullable=False, server_default="0"),
        sa.Column("setup_fee", sa.Numeric(10, 2), nullable=False, server_default="0"),
        sa.Column("slider_values", sa.JSON(), nullable=True),
    )
    op.create_index("ix_cart_items_user_id", "cart_items", ["user_id"])
    op.create_index("ix_cart_items_product_id", "cart_items", ["product_id"])


def downgrade() -> None:
    op.drop_index("ix_cart_items_product_id", table_name="cart_items")
    op.drop_index("ix_cart_items_user_id", table_name="cart_items")
    op.drop_table("cart_items")
