<?php

namespace App\Services\Notification\Exceptions;

use App\Exceptions\Throwable;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Log;

class OperatorNotConnectedException extends Exception
{
    public $message;

    public function __construct(string $message = "", int $code = 500, ?Throwable $previous = null)
    {
        $this->message = $message;

        parent::__construct($message, $code, $previous);
    }

    /**
     * Report the exception.
     */
    public function report(): void
    {
        Log::channel('notification_service')
            ->error(OperatorNotConnectedException::class,[__('messages.operator_could_not_connect')]
        );
    }

    /**
     * Render the exception into an HTTP response.
     */
    public function render(): JsonResponse
    {
        return response()->json([
            'message' => $this->message
        ], $this->code);
    }
}
