<?php
/**
 * app/controllers/api/auth.php
 *
 * This is the api authentication controller.
 *
 * @version 3.0
 * @author  Joey Kimsey <Joey@thetempusproject.com>
 * @link    https://TheTempusProject.com
 * @license https://opensource.org/licenses/MIT [MIT LICENSE]
 */
namespace TheTempusProject\Controllers\Api;

use TheTempusProject\Models\User;
use TheTempusProject\Classes\ApiController;
use TheTempusProject\Houdini\Classes\Views;
use TheTempusProject\Models\Token;

class Auth extends ApiController {
    public static $tokens;

    public function __construct() {
        parent::__construct();
        self::$tokens = new Token;
    }

    public function refresh() {
        $token = self::$tokens->refresh( self::$authToken->ID );
        if ( empty( $token ) ) {
            $responseType = 'error';
            $response = 'IRDK';
        } else {
            $responseType = 'token';
            $response = $token;
        }
        Views::view( 'api.response', ['response' => json_encode( [ $responseType => $response ], true )]);
    }
}