"""Denormalize product and marketplace data onto cart_items and order_items.

Revision ID: cart_0002
Revises: cart_0001
Create Date: 2026-02-26
"""

import sqlalchemy as sa
from alembic import op

revision = "cart_0002"
down_revision = "cart_0001"
branch_labels = None
depends_on = None


def upgrade():
    # -- cart_items: denormalized product data --
    op.add_column("cart_items", sa.Column("product_title", sa.String(512), nullable=True))
    op.add_column("cart_items", sa.Column("product_slug", sa.String(512), nullable=True))
    op.add_column("cart_items", sa.Column("product_image", sa.Text, nullable=True))
    op.add_column("cart_items", sa.Column("product_brand", sa.String(255), nullable=True))
    op.add_column("cart_items", sa.Column("product_regular_price", sa.Numeric(12, 2), nullable=True))
    op.add_column("cart_items", sa.Column("product_special_price", sa.Numeric(12, 2), nullable=True))
    op.add_column("cart_items", sa.Column("product_price_currency", sa.String(16), nullable=True))

    # -- cart_items: denormalized marketplace data --
    op.add_column("cart_items", sa.Column("market_place_name", sa.String(255), nullable=True))
    op.add_column("cart_items", sa.Column("market_place_container_id", sa.Integer, nullable=True))

    # -- order_items: denormalized product fields --
    op.add_column("order_items", sa.Column("product_slug", sa.String(512), nullable=True))
    op.add_column("order_items", sa.Column("product_image", sa.Text, nullable=True))


def downgrade():
    op.drop_column("order_items", "product_image")
    op.drop_column("order_items", "product_slug")

    op.drop_column("cart_items", "market_place_container_id")
    op.drop_column("cart_items", "market_place_name")
    op.drop_column("cart_items", "product_price_currency")
    op.drop_column("cart_items", "product_special_price")
    op.drop_column("cart_items", "product_regular_price")
    op.drop_column("cart_items", "product_brand")
    op.drop_column("cart_items", "product_image")
    op.drop_column("cart_items", "product_slug")
    op.drop_column("cart_items", "product_title")
