<?php

namespace App\Http\Controllers;

use App\Jobs\HubSpot\UpdateCustomer;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Support\Facades\Log;

class HubspotController extends BaseController
{
    public function customerUpdate(Request $request)
    {
        Log::info('Received Hubspot Call: ' . $request->getContent());
        $hubspotData = json_decode($request->getContent(), true);

        foreach ($hubspotData as $singleEventData) {
            if ($singleEventData['propertyValue'] == 'true') {
                UpdateCustomer::dispatch($singleEventData);
            } else {
                Log::info('Ignoring HubSpot update - no webshop access');
            }
        }
    }
}
