<?php

namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update;


use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateAccountCosQuota;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Traits\ProductManagerHandler;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * 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->getLastResult()->getLastErrorCode());
            return false;
        }

        return true;
    }
}