<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update;


use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\ApiService;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Account;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Create\CreateAccountCosQuota;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Traits\ProductManagerHandler;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 08.11.19
 * Time: 12:15
 * Class UpdateAccountPassword
 */
class UpdateAccountPassword extends ApiService
{
    use ProductManagerHandler;

    /**
     * @return bool
     */
    public function isValid()
    {
        if(!$this->formData['id'])
        {
            $this->setError('Account Id name can not be found.');
            return false;
        }

        return parent::isValid(); // TODO: Change the autogenerated stub
    }

    /**
     * @return bool|mixed
     */
    public function process()
    {
        $model = new Account();
        $model->setId($this->formData['id']);
        $model->setPassword($this->formData['password']);

        $result = $this->api->account->setPassword($model);

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

        return true;
    }
}