<?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\Ressource;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateRessourceCosQuota;
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 UpdateRessourcePassword
 */
class UpdateRessourcePassword extends ApiService
{
    use ProductManagerHandler;

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

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

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

        $result = $this->api->ressource->setPassword($ressource);

        if(!$result)
        {
            $this->setError($this->api->ressource->getLastResult()->getLastErrorCode());
            return false;
        }

        return true;
    }
}