<?php

use FiloBlu\Esb\Api\Data\ConsumerInterface;
use FiloBlu\Esb\Api\Data\MessageInterface;
use FiloBlu\Esb\Api\Data\MessageInterfaceFactory;
use FiloBlu\Refilo\Model\Consumer\NewsletterConsumer;
use Magento\Framework\App\Bootstrap;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\State;
use Magento\Framework\DataObject;

require __DIR__ . '/../../../../../app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get(State::class);
$state->setAreaCode('adminhtml');
$objectManager = ObjectManager::getInstance();

//$data = json_decode('{}', true);

$data = [
    'form_type' => 'newsletter',
    'fields' => [
        "source" => 'POPUP',
       "email"=>"carmine+34@filoblu.com",
       "firstname"=>"Carmine",
       "lastname"=> "Esposito",
        "dob" => "2020-07-22 14:05:54",
        "gender"=> "Male",
        "newsletter_collection"=> "season",
        "phone"=> "33330945454",
        "country"=> "IT",
        "newsletter_privacy"=> "true",
        "store"=> "en",
        "collections" => "ss20",
        "language" => "IT",
        "website_name" => "https://www.google.it"
    ]
];

///////////////////////////////////////////////////////////////////////////////
///
///
//////////////////////////////////////////////////////////////////////////////

$payload = new DataObject($data);



/** @var  MessageInterface $message */
$message = $objectManager->create(MessageInterfaceFactory::class)->create();
$message->setPayload($payload);

/** @var  ConsumerInterface $formConsumer */
$formConsumer = $objectManager->get(NewsletterConsumer::class);


///////////////////////////////////////////////////////////////////////////////
///
/// Dispatch
///
//////////////////////////////////////////////////////////////////////////////

$formConsumer->consume($message);
