// Cause I want to have a properly standardize product data cause I hate those "nodes" thinggy
// and to prevent render error in case some data doesn't exist, I want a default value

export const formatProductData = (product) => {

    if(!product) return
    
    return {
        id: product?.id || null,
        handle: product?.handle || "",
        title: product?.title || "",
        createdAt: product?.createdAt,
        collections: product?.collections?.nodes || null,
        descriptionHtml: product?.descriptionHtml || "",
        tags:product?.tags || null,
        images: product?.images?.nodes || null,
        selected: (product?.metafield?.key == "selected") ? product?.metafield?.value == "true" : false, // cause I want to have a true false value, somehow BE return text value "true", thus == used to convert it to proper boolean value
        minVariantPrice: product?.priceRange?.minVariantPrice || {amount:0 , currencyCode:''},
        maxVariantPrice: product?.priceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
        compareAtPriceRangeMinVariantPrice: product?.compareAtPriceRange?.minVariantPrice || {amount:0 , currencyCode:''},
        compareAtPriceRangeMaxVariantPrice: product?.compareAtPriceRange?.maxVariantPrice || {amount:0 , currencyCode:''},
        productType: product?.productType || null,
        variants: product?.variants?.nodes || null,
        
    }

}