<?php
namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Services\Update;
use ModulesGarden\Servers\ZimbraEmail\App\Enums\Size;
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\CreateAccount;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 18.09.19
 * Time: 11:09
 * Class UpdateAccount
 */
class UpdateAccount extends CreateAccount
{

    /**
     * @return bool|mixed|Account|void
     */
    protected function process()
    {
        /**
         *
         */
        $model = $this->getModel();

        /**
         * update account in ZIMBRA
         */
        $result = $this->api->account->update($model);

        /**
         * problem with create account
         */
        if(!$result)
        {
            $this->setError($this->api->account->getError());
            return false;
        }

        return $result;
    }

    /**
     * @return Account
     */
    public function getModel()
    {
        $account = new Account();
        /**
         *  set account attributes
         */
        $account->setId($this->formData['id']);

        $account->setAttr(Account::ATTR_FIRSTNAME, $this->formData['firstname']);
        $account->setAttr(Account::ATTR_LASTNAME, $this->formData['lastname']);
        $account->setAttr(Account::ATTR_PHONE, $this->formData['phone']);
        $account->setAttr(Account::ATTR_MOBILE_PHONE, $this->formData['mobile_phone']);
        $account->setAttr(Account::ATTR_FAX, $this->formData['fax']);
        $account->setAttr(Account::ATTR_PAGER, $this->formData['pager']);
        $account->setAttr(Account::ATTR_HOME_PHONE, $this->formData['home_phone']);
        $account->setAttr(Account::ATTR_COUNTRY, $this->formData['country']);
        $account->setAttr(Account::ATTR_STATE, $this->formData['state']);
        $account->setAttr(Account::ATTR_PROF_TITLE, $this->formData['title']);
        $account->setAttr(Account::ATTR_POSTAL_CODE, $this->formData['post_code']);
        $account->setAttr(Account::ATTR_CITY, $this->formData['city']);
        $account->setAttr(Account::ATTR_STREET, $this->formData['street']);
        $account->setAttr(Account::ATTR_COMPANY, $this->formData['company']);
        $account->setAttr(Account::ATTR_ACCOUNT_STATUS, $this->formData['status']);
        $account->setAttr(Account::ATTR_DISPLAY_NAME, $this->formData['display_name']);

        return $account;

    }
}