<?php

namespace Api\Logout;

use Khofmann\Api\Api;
use Khofmann\Models\User\User;
use Khofmann\Request\Request;
use Khofmann\Response\Response;

/**
 * Logout route handlers
 */
class Logout extends Api
{
  /**
   * Logout POST handler
   *
   * Logout a user. User is retrieved using the authentication `token`.
   *
   * Returns user.
   *
   * @throws 404 User not found
   */
  public function post(): void
  {
    // Get user auth token.
    $token = Request::token();

    // Log out.
    Response::json(User::getByToken($token)->logOut());
  }
}
