<?php

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


use ThurData\Servers\KerioEmail\App\Enums\Kerio;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Domain;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 10.10.19
 * Time: 15:21
 * Class UnsuspendDomain
 */
class UnsuspendDomain extends ApiService
{

    public function process()
    {
        $domain = $this->api->repository()->domains->getByName($this->formData['domain']);
        if(!$domain)
        {
            $this->setError($this->api->account->getLastResult()->getLastErrorCode());
            return false;
        }

        $domain->setAttrs([
            Domain::ATTR_DOMAIN_STATUS => Kerio::ACC_STATUS_ACTIVE,
            Domain::ATTR_MAIL_STATUS    => Kerio::ENABLED,
            ]);

        $response = $this->api->domain->update($domain);
        if(!$response)
        {
            $this->setError($this->api->domain->getLastResult()->getLastErrorCode());
            return false;
        }

        return true;
    }
}