<?php

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


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

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 02.10.19
 * Time: 08:23
 * Class DeleteDistributionList
 */
class DeleteDistributionList extends ApiService
{

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

        return parent::isValid();
    }

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

        $result = $this->api->distributionList->delete($list);

        if(!$result)
        {
            $this->setError($this->api->distributionList->getError());
            return false;
        }

        return true;
    }
}