<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Sso;

use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Connection;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\ApiService;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Account;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * 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']
        ];
    }

}