<?php

namespace Yajny\EventsYj\Library\Boostiny;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Log;

class Conversion
{
    private $query;
    private $api_key;
    private $countries;

    public function __construct($country, $currency, $amount, $click_id, $order_id, $created_at, $store_slug)
    {
        $this->countries = ['eg' => 'EGY', 'ae' => 'ARE', 'kw' => 'KWT', 'sa' => 'SAU'];
        $client_id = '';
        if ($store_slug == 'amazon') {
            $client_id = 'amazon-egypt';
            $this->api_key = 'n9S6-suBKXwSCoTSvwvSXMOVbJA2HR0GgKdRltSdKNA';
            $country = 'eg';
        }
        if ($store_slug == 'amazon-sa') {
            $client_id = 'amazon-ksa';
            $this->api_key = 'jnp0q902OYNRrKenCmYnY_1EL4T3aBrW0OCGjssmn34';
            $country = 'sa';
        }
        if ($store_slug == 'aliexpress') {
            $client_id = 'aliexpress1';
            $this->api_key = 'ocUjZ8UMMKB5jNLcoOuko14gypOS5Z1m6eOUt5gzs9c';
        }
        $currency = 'USD';
        $this->query = [
            'client' => $client_id,
            'country' => $this->countries[$country],
            'currency' => $currency,
            'click_id' => $click_id,
            'order_id' => $order_id,
            'amount' => $amount,
            'created_at' => $created_at,
        ];

    }

    public function callPostback()
    {
        $client = new Client();
        $request = $client->request(
            'GET',
            'https://track.arabytracking.net/link/conversion',
            [
                'query' => $this->query,
                'headers' => [
                    'Authorization' => $this->api_key,
                ],
            ]
        );
        // Log::error('user', json_decode($request->getBody(), true));
    }

}
