
export const fromWCCartItems = wcCartItem => {
    const paymentInfo = wcCartItem['payment_info'] || {};
    const totalPrices = wcCartItem['total_prices'] || {};

    return {
        idPackage: wcCartItem['package_id'],
        key: wcCartItem.key,
        packageName: wcCartItem['package_name'],
        quantity: wcCartItem.quantity,

        idCommercialLead: wcCartItem['commercial_lead_id'],
        commercialLead: wcCartItem['commercial_lead'],
        country: wcCartItem.country ? wcCartItem.country : [],

        areAdditionalAvailable: wcCartItem['are_additional_available'],
        additionalPackages: wcCartItem['additional_packages'] ? wcCartItem['additional_packages'].map(additionalPackageItem => ({
            idAdditionalPackage:  additionalPackageItem['package_id'],
            packageName: additionalPackageItem['package_name'],
            prices: {
                fixedExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['fixed_extra'] : 0,
                recurrentExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['recurrent_extra'] : 0,
                servicesExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['services_extra'] : 0,
            }
        })) : [],

        areOptionsAvailable: wcCartItem['are_options_available'],
        options: wcCartItem.options ? wcCartItem.options.map(optionPackageItem => ({
            idOptionPackage:  optionPackageItem['package_id'],
            packageName: optionPackageItem['package_name'],
            groupName: optionPackageItem['group_name'],
            prices: {
                fixedExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['fixed_extra'] : 0,
                recurrentExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['recurrent_extra'] : 0,
                servicesExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['services_extra'] : 0,
            }
        })) : [],

        bids: wcCartItem.bids,

        idPayType: paymentInfo.id,
        payType: paymentInfo.type,
        periodUnit: paymentInfo['period_unit'] || 'month',
        idPrice: paymentInfo.id,
        fixedPrice: paymentInfo['fixed_extra'] !== undefined ? paymentInfo['fixed_extra'] : 0,
        recurrentPrice: paymentInfo['recurrent_extra'] !== undefined ? paymentInfo['recurrent_extra'] : 0,
        servicesPrice: paymentInfo['services_extra'] !== undefined ? paymentInfo['services_extra'] : 0,

        totalPrices: {
            fixedPrice: totalPrices['fixed_extra'] !== undefined ? totalPrices['fixed_extra'] : 0,
            recurrentPrice: totalPrices['recurrent_extra'] !== undefined ? totalPrices['recurrent_extra'] : 0,
            servicesPrice: totalPrices['services_extra'] !== undefined ? totalPrices['services_extra'] : 0,
        }
    };
};