from __future__ import annotations

from models.market import Product


def massage_full_product(product: Product) -> dict:
    """
    Convert a Product ORM model to a dictionary with all fields.
    Used for rendering product detail pages.
    """
    from bp.browse.services import _massage_product

    gallery = []
    if product.image:
        gallery.append(product.image)

    d = {
        "id": product.id,
        "slug": product.slug,
        "title": product.title,
        "brand": product.brand,
        "image": product.image,
        "description_short": product.description_short,
        "description_html": product.description_html or "",
        "suma_href": product.suma_href,
        "rrp": float(product.rrp) if product.rrp else None,
        "special_price": float(product.special_price) if product.special_price else None,
        "regular_price": float(product.regular_price) if product.regular_price else None,
        "images": gallery or [img.url for img in product.images],
        "all_image_urls": gallery or [img.url for img in product.images],
        "sections": [{"title": s.title, "html": s.html} for s in product.sections],
        "stickers": [s.name.lower() for s in product.stickers],
        "labels": [l.name for l in product.labels],
        "nutrition": [{"key": n.key, "value": n.value, "unit": n.unit} for n in product.nutrition],
        "allergens": [{"name": a.name, "contains": a.contains} for a in product.allergens],
        "is_liked": False,
    }

    return _massage_product(d)


