<?php

namespace Benhauer\Salesmanago\Observer;

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

class CustomerModified extends SalesmanagoAbstractObserver
{
    public function hookAct(Observer $observer)
    {
        try {
            $customer = $this->getCustomerById($this->getCustomer($observer)->getId());

            $connectSalesManago = $this->getConnectSalesManago();

            $customer['options'] = isset($customer['options'])
                ? $customer['options']
                : '';

            $this->upsertContact($customer, $connectSalesManago, SalesmanagoAbstractObserver::UPSERT_FLAG_NO_CHECK);

        } catch (\Exception $e) {
            $this->logger->critical($e->getMessage());
        }
    }

    /**
     * @param object $observer;
     * @return object Customer;
    */
    public function getCustomer($observer)
    {
        $customer = $this->customerRepositoryInterface->get($observer->getData('email'));
        return $customer;
    }
}
