<?php

declare(strict_types=1);

namespace App\Http\Controllers\API\V1\Auth;

use Dingo\Api\Http\Response;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;
use PHPOpenSourceSaver\JWTAuth\JWTGuard;

/**
 * Class LogoutAction
 *
 * @package App\Http\Controllers\API\V1\Auth
 */
final class LogoutAction extends Controller
{
    use Helpers;

    /**
     * @return \Dingo\Api\Http\Response
     */
    public function __invoke(): Response
    {
        /** @var JWTGuard $guard */
        $guard = auth('jwt');

        $guard->setUser(auth()->user());
        $guard->logout();

        return $this->response->accepted(null, ['message' => 'Successfully logged out']);
    }
}
