<?php

namespace Benhauer\Salesmanago\Observer;

use \Psr\Log\LoggerInterface;

use \Magento\Framework\Event\Observer;

use \Benhauer\Salesmanago\Helper\Tagger;
use \Benhauer\Salesmanago\Observer\AbstractObserver as SalesmanagoAbstractObserver;

class CustomerRegister extends SalesmanagoAbstractObserver
{
    public function hookAct(Observer $observer)
    {
        try {
            $customerId = $observer->getCustomer()->getId();
            $contact = $this->getCustomerById($customerId);
            $connectSalesManago = $this->getConnectSalesManago();

            $contact = $this->tagger
                ->setModel($this->model)
                ->setTags($contact, Tagger::T_REGISTER);

            $this->upsertContact($contact, $connectSalesManago, SalesmanagoAbstractObserver::UPSERT_FLAG_ALL_DATA);

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