<?php
namespace Fifa\ConnectServiceBus\Sdk\Authentication\Model;

use stdClass;

/**
 * Class Token
 * @package Fifa\ConnectServiceBus\Sdk\Authentication\Model
 */
class Token
{
    /**
     * @var string
     */
    private $type;

    /**
     * @var int
     */
    private $expiresAt;

    /**
     * @var string
     */
    private $accessToken;

    /**
     * Constructor
     *
     * @param stdClass $responseData
     */
    public function __construct(stdClass $responseData)
    {
        $this->type = $responseData->token_type ?? '';
        $this->expiresAt = isset($responseData->expires_in) ? time() + $responseData->expires_in : 0;
        $this->accessToken = $responseData->access_token ?? '';
    }

    /**
     * String representation for the object
     *
     * @return string
     */
    public function __toString()
    {
        return  'Type: ' . $this->getType()
            . ', ExpiresAt: ' . $this->getExpiresAt()
            . '. AccessToken: ' . $this->getAccessToken();
    }

    /**
     * Getter for token type
     *
     * @return string
     */
    public function getType(): string
    {
        return $this->type;
    }

    /**
     * Getter for access token
     *
     * @return string
     */
    public function getAccessToken(): string
    {
        return $this->accessToken;
    }

    /**
     * Getter for expiration time
     *
     * @return string
     */
    public function getExpiresAt()
    {
        return $this->expiresAt;
    }
}