<?php

namespace Benhauer\Salesmanago\Observer;

use \Magento\Framework\Event\Observer;
use \Benhauer\Salesmanago\Observer\AbstractObserver as SalesmanagoAbstractObserver;

class WishlistModified extends SalesmanagoAbstractObserver
{
    public function hookAct(Observer $observer)
    {
        try {
            $eventItems = $observer->getEvent()->getItems();
            $product = reset($eventItems)->getProduct();
            $customerId = reset($eventItems)->getWishlist()->getCustomerId();
            $customer = $this->customerRepositoryInterface->getById($customerId);
            $customerEmail = $customer->getEmail();
            $productId = $product->getEntityId();
            $productName = $product->getName();
            $productValue = round($product->getPrice(), 2);
            $dateTime = $this->objDate->date();
            $connectSalesManago = $this->getConnectSalesManago();

            $eventData = [
                'date' => $dateTime->format('c'),
                'products' => $productId,
                'value' => $productValue,
                'detail1' => $productName,
                'description' => 'WISHLIST',
            ];
            $contact = ['email' => $customerEmail];

            $connectSalesManago->contactExtEvent(
                "OTHER",
                $eventData,
                $contact,
                ''
            );
        } catch (\Exception $e) {
            $this->logger->critical($e->getMessage());
        }
    }
}
