<?php

namespace Support;

use APIResponse;
use Illuminate\Events\Dispatcher;
use Tymon\JWTAuth\JWTAuthFilter;

class JWTBandAuthFilter extends JWTAuthFilter
{
    /**
     * @var \Illuminate\Events\Dispatcher
     */
    protected $events;

    /**
     * @var \Support\JWTBandAuth
     */
    protected $auth;

    public function __construct(Dispatcher $events, JWTBandAuth $auth)
    {
        $this->events = $events;
        $this->auth = $auth;
    }

    /**
     * Fire event and return the response
     *
     * @param  string   $event
     * @param  string   $error
     * @param  integer  $status
     * @return mixed
     */
    protected function respond($event, $error, $status, $payload = [])
    {
        $response = $this->events->fire($event, $payload, true);

        return $response ?: APIResponse::fail($status, [
            'band_auth' => $error,
        ]);
    }
}
