<?php

namespace App\Services\Integration\Integration;

use App\Services\Integration\Interface\ConnectionInterface;

class Connection extends API implements ConnectionInterface
{

    public static function get($url,$data)
    {
        $response = self::getRequest($url,$data);
        // $response = self::executeRequest($url,$data, 'GET');
        return $response;
    }
    public static function getItem($url)
    {
         $url = config('app.url').'/'.$url;
        $response = self::getItemRequest($url);
        return $response;
    }

    public static function create($url,$data)
    {
        $curl = curl_init();

        $response = self::postRequest($url,$data);
        return $response;
    }

    public static function update($url,$data)
    {
        $url = config('app.url').'/'.$url;
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => '',
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => 'GET',
            CURLOPT_HTTPHEADER => array(
                'Cookie: XSRF-TOKEN=eyJpdiI6ImJLZTNsemhRR0ZIL2dhRWc5UHpVY2c9PSIsInZhbHVlIjoibUFLNlROY0phbFFlVFVtdTVIV0VNcnFhSWJyZG5iVEhhVjFraWVWTmZ4eGM5ekl0N0FweFljWGRtbGd6LzljV3Y2ZWhTN1ArNXduc3hMWGJDNmhQOFdFMVVId1pQTzdZZTBNck5LMHFaZHloUllwVHJkcEhIRHBEcHFZWHF6dXoiLCJtYWMiOiIwYzQ0YzBjMjUwNjhhNjMyMWEwOWY3YjI0MTczM2E4NTIzODA4ZGFkN2FlNWYzNzFiOWU2YjhlNzVkMTE1YjUwIiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6IldZZnR6NkFHYU5MSVUwVEp1dmwxUFE9PSIsInZhbHVlIjoiZlpBUWIvajFBclcwMnpFRVpOT0toMnVWL1pHN3daYkF1cm5UT0dUb2pUVHJpQzl3V0VPeFJJZ1NFcWR1MGVSaXBaRTIvbXVVazZHUnV5U3BYcHo1aUNoeklJWGFKRHBaSzFxVFYxM2ovd2JobkhCbldBOHZzR1JvclVZOFVTOHoiLCJtYWMiOiI0YTdlYjRkOTVhOTY4MmE3NWNiNDdlYzEwZWFiZTcyZjRmZTczNzRkMWM1YTk4NGJhMjExMTg1N2Y5MWI2ZGU5IiwidGFnIjoiIn0%3D'
            ),
        ));

        $response = curl_exec($curl);
        $response = json_decode($response);
        curl_close($curl);
        return $response;
    }
}
