<?php

namespace Edeclic\PrestashopBridgeBundle\EventListener;

use Edeclic\PrestashopBridgeBundle\Utils\PrestashopBridge;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;

class LogoutListener implements LogoutHandlerInterface
{
    protected $pathToPrestashop;
    protected $idShop;
    protected $cookieKey;
    protected $avoidMode;

    /**
     * @param $config
     */
    public function setConfig($config)
    {
        $this->idShop = $config['shop_id'];
        $this->pathToPrestashop = $config['presta_path'];
        $this->cookieKey = $config['cookie_key'];
        $this->avoidMode = $config['avoid_mode'];
    }

    public function logout(Request $Request, Response $Response, TokenInterface $Token)
    {
        if (!$this->avoidMode) {
            $prestaBridge = new PrestashopBridge($this->pathToPrestashop, $this->idShop, $this->cookieKey);
            $prestaBridge->logout();
        }

    }
}