<?php

namespace Extension\CbUtilityPackage;

use Application\Config;
use Application\CrmPayload;
use Application\CrmResponse;
use Application\Session;
use Application\Model\Configuration;
use Application\Request;

class ExtraParams extends Common
{
    public function __construct()
    {
        parent::__construct();
        $this->send_currency = Config::extensionsConfig('CbUtilityPackage.send_currency');
        $this->currency      = Config::extensionsConfig('CbUtilityPackage.currency');
    }

    public function sendCurrency()
    {
        if (
            empty($this->send_currency) ||
            Request::attributes()->get('action') == 'prospect'
        ) {
            return;
        }
        
        CrmPayload::set('currency', $this->currency);
    }

    public function sendExtraParams()
    {
        if (
            Request::attributes()->get('action') == 'prospect'
        ) {
            return;
        }

        $formPayload = Request::form()->all();
        $isSplit = CrmPayload::get('meta.isSplitOrder');
        if (!empty($isSplit)) {
            $extraParams = array('split_route_id');
        } else {
            $extraParams = array('route_id', 'stripe_shipping_price');
        }
        if(!empty($formPayload))
        {
            foreach ($extraParams as $value)
            {
                if(isset($formPayload[$value]))
                {
                    if($value == 'split_route_id') {
                        CrmPayload::set('route_id', $formPayload[$value]);
                    } else {
                        CrmPayload::set($value, $formPayload[$value]);
                    }
                }
            }
        }
    }

}