<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use GuzzleHttp\Client;

class CI4 implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $data;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
       
        try {
            $client = new Client();
            $res = $client->request('POST', 'http://localhost/backoffice/takings', [
                'headers' => [
                    'x-api-key' => "YNNUJ4We7RzppE3wmLwxAS7BY9G-WJhulW9OzBNWke5RUbIvr479KQXF0KJ7O62Q",
                ],
                'json'    => [
                    'body' => $this->data
                ]
            ]);
            $response = $res->getBody();
            \Log::channel('ci4')->info($response);
        } catch(\Exception $e) {
            \Log::channel('ci4')->info($e->getMessage());
        }
    }
}
