<?php

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


use ModulesGarden\Servers\ZimbraEmail\App\Libs\Zimbra\Components\Api\Soap\Interfaces\AbstractModel;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 09.09.19
 * Time: 15:20
 * Class Domain
 */
class Domain extends AbstractModel
{
    const ATTR_ALIAS_TARGET_ID      = 'zimbraDomainAliasTargetId';
    const ATTR_DOMAIN_TYPE          = 'zimbraDomainType';
    const ATTR_DESCRIPTION          = 'description';
    const ATTR_DOMAIN_STATUS        = 'zimbraDomainStatus';
    const ATTR_MAIL_STATUS          = 'zimbraMailStatus';
    const ATTR_MAIL_DOMAIN_QUOTA    = 'zimbraMailDomainQuota';
    const TYPE_ALIAS                = 'alias';

    protected $id;
    protected $name;
    protected $attrs;

    /**
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param mixed $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * @return mixed
     */
    public function getAttrs()
    {
        return $this->attrs;
    }

    /**
     * @param mixed $attrs
     */
    public function setAttrs($attrs)
    {
        $this->attrs = $attrs;
    }

    /**
     * @param $key
     * @param null $value
     */
    public function setAttr($key, $value = null)
    {
        $this->attrs[$key] = $value;
    }

    /**
     * @param $key
     * @return mixed
     */
    public function getAttr($key)
    {
        return $this->attrs[$key];
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @param $attrs
     */
    public function setA($attrs)
    {
        foreach($attrs as $attr)
        {
            $this->setAttr($attr['N'], $attr['DATA']);
        }

    }

    /**
     * @return bool
     */
    public function isAlias()
    {
        $targetId = $this->getAttr(self::ATTR_ALIAS_TARGET_ID);
        return $targetId ? true : false;
    }

}