<?php

namespace App\Jobs;

use App\Exceptions\ApiErrorException;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Log;
use Exception;

class SlackLogJob extends Job
{

    protected $slack;

    public $tries = 1;
    public $timeout = 60;

    public function __construct($slack)
    {
        $this->slack = $slack;
    }

    public function handle()
    {
        try {

            $client = new Client();
            $client->request('POST', config('app.log_slack'),
                [
                    'headers' => [
                        'Content-Type' => 'application/json'
                    ],
                    'body' => json_encode($this->slack),
                ]);

        } catch (Exception $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error('--SlackLogJob RequestException--');
            Log::error($message);
        } catch (RequestException $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error('--SlackLogJob RequestException--');
            Log::error($message);
        } catch (ApiErrorException $e) {
            $message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
            Log::error('--SlackLogJob ApiErrorException--');
            Log::error($message);
        }
    }

}
