<?php
declare(strict_types=1);

use FiloBlu\Peuterey\Helper\ConsentsProfilingHelper;
use Magento\Framework\App\Bootstrap;

require __DIR__ . '/../../../../app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();

$request = [
    "create_update_contact" => [
        "request" => [
            "contact" => [
                "email" => "carmine.mele@filoblu.com",
                "firstName" => "Carmine",
                "lastName" => "Mele",
                "phone" => "+393933112134",
                "fieldValues" => [
                    [
                        "field" => "1",
                        "value" => "IT"
                    ],
                    [
                        "field" => "10",
                        "value" => "CUSTOMER"
                    ],
                    [
                        "field" => "9",
                        "value" => "CHECKOUT"
                    ],
                    [
                        "field" => "3",
                        "value" => "it_IT"
                    ]
                ]
            ]
        ]
    ],
    "list_subscription" => [
        "request" => [
            "contactList" => [
                "list" => "1",
                "status" => "1",
                "contact" => "134080"
            ]
        ]
    ]
];

/** @var ConsentsProfilingHelper $helper */
$helper = $objectManager->get(ConsentsProfilingHelper::class);

// TestConfiguration
$consentEnable = $helper->isMarketingConsentsEnabled();
$consentType = $helper->getConsentTypeConfiguration();
$consentMapping = $helper->getConsentsCustomerMapData();
$marketingProfile = $helper->getActiveCampaignFieldId(ConsentsProfilingHelper::MARKETING_PROFILE);
$marketingProfileSubscription = $helper->getActiveCampaignFieldId(ConsentsProfilingHelper::MARKETING_PROFILE_SUBSCRIPTION_DATE);
$marketingProfileUnsubscription = $helper->getActiveCampaignFieldId(ConsentsProfilingHelper::MARKETING_PROFILE_UNSUBSCRIPTION_DATE);

//_________________________________

//Test Core Methods

// exception test
$emptyData = $helper->getConsentsSubscriptionData('pippo@filoblu.com');

// Success test with email in consents_subscription table
$consentsSubscriptionData = $helper->getConsentsSubscriptionData($request['create_update_contact']['request']['contact']['email']);

//exception test
$oldRequestReturn = $helper->addConsentDataToRequest($request, 'pippo@filoblu.com');

// Success test with email in consents_subscription table with revoked consent
$successRequestUpdated = $helper->addConsentDataToRequest($request, $request['create_update_contact']['request']['contact']['email']);

// Success test with email in consents_subscription table with valid consent
$successRequestUpdatedNotRevoked = $helper->addConsentDataToRequest($request, 'account34@filoblu.com');

