<?php

class Authentication extends CurlRequest 
{
    
    private $name;
    private $password;
    private $token;
    private $expirationDate;
    
    public function __construct($name, $password, Environment $envirounment )
    {
        
        $this->name = $name;
        $this->password = $password;

        $urlrequest = $envirounment->getApiUrl().'v1/authenticate';
        $jsonsend = json_encode(
            Array(
                "name" => $name,
                "password" => $password   
            )                     
        );

        $requestResult = parent::callAPI($urlrequest,'POST',$jsonsend,['Content-Type: application/json'],false,$retorno);
        $this->token = $requestResult->Token;
        $this->expirationDate = $requestResult->ExpirationDate;

    }
    
    /**
     * Gets the name identification 
     *
     * @return the user name 
     */
    public function getName()
    {
        return $this->name;
    }
    
    /**
     * Gets the password identification 
     *
     * @return the user password
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Get the value of token
     */ 
    public function getToken()
    {
        return $this->token;
    }

    /**
     * Get the value of expirationDate
     */ 
    public function getExpirationDate()
    {
        return $this->expirationDate;
    }

}