<?php

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


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

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * 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->getLastResult()->getLastErrorCode());
            return false;
        }

        return true;
    }
}