<?php
namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Sso;

use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Connection;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 12.11.19
 * Time: 17:24
 * Class ClientSingleSignOn
 */
class ClientSingleSignOnToken extends ApiService
{

    /**
     *
     * @return mixed|string
     * @throws \SoapFault
     */
    public function process()
    {
        $account = new Account();
        $account->setName($this->formData['mail']);
        $account->setId($this->formData['id']);

        $result = $this->api->account->delegateAuth($account);

        if(!$result)
        {
            $this->setError($this->api->account->getError());
            return false;

        }

        return [
            'authToken' => $result->getResponseBody()['DELEGATEAUTHRESPONSE']['AUTHTOKEN']['DATA'],
        '   lifeTime' =>$result->getResponseBody()['DELEGATEAUTHRESPONSE']['LIFETIME']['DATA']
        ];
    }

}