<?php

namespace Sipago\WooCommerce\SipagoCheckout\ClientSipago;
use Sipago\WooCommerce\SipagoCheckout\Helpers\LogHandler;

class SipagoLogRemoteRest{

    const POST_LOG = 'https://infra.sipago.online/tdk-api-remote-log/services/api/v1/log';

    public $clientId;


    /**
     * @var LogHandler
     */
    protected $log;



    public function __construct($clientId){

        $this->clientId = $clientId;

    }

    public function putLogs($idOrder,$code,$dataRaw){

        try {
            $data = [
                'id' => $idOrder,
                'id2' => $this->clientId,
                'code' => $code,
                'dataRaw' => $dataRaw
            ];

            $jsonData = json_encode($data);

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, static::POST_LOG);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 2.14);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2.14);
            curl_setopt($ch, CURLOPT_HTTPHEADER, [
                'Content-Type: application/json',
                'Content-Length: ' . strlen($jsonData)
            ]);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

            $response = curl_exec($ch);

            if (curl_errno($ch)) {
                // Error en la petición curl
                // Similar a la excepción en GuzzleHttp
            }

            curl_close($ch);

        } catch(Exception $e) {
            // Manejo de excepciones
        }

    }


}