"""Catalog_ListItems — Beletage product catalog."""
from __future__ import annotations

from ..xml_utils import text_under, decimal_under, datetime_under, sysitem_name, to_jsonable, int_under


def parse(el) -> dict | None:
    item_code = text_under(el, 'ItemCode') or text_under(el, 'CatalogItemCode')
    if not item_code:
        return None
    return {
        'item_code': item_code,
        'item_name': text_under(el, 'Name') or text_under(el, 'ItemName'),
        'cpv_code': sysitem_name(el, 'CpvCode'),
        'unit_price': decimal_under(el, 'UnitPrice') or decimal_under(el, 'Price'),
        'currency': sysitem_name(el, 'Currency'),
        'last_updated': datetime_under(el, 'LastUpdate'),
        'details': to_jsonable(el),
    }
