<?php

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


use ModulesGarden\Servers\ZimbraEmail\App\Enums\Zimbra;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\ApiService;
use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Models\Domain;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 10.10.19
 * Time: 15:20
 * Class SuspendDomain
 */
class SuspendDomain extends ApiService
{

    public function isValid()
    {

        return parent::isValid();
    }

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

        $domain->setAttrs([
            Domain::ATTR_DOMAIN_STATUS  => Zimbra::ACC_STATUS_SUSPEND,
            Domain::ATTR_MAIL_STATUS    => Zimbra::DISABLED,

        ]);

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

        return true;
    }
}