<?php

namespace patest\ArrayType;

use \WsdlToPhp\PackageBase\AbstractStructArrayBase;

/**
 * This class stands for ArrayOfCrm.DuplicationCheckRule ArrayType
 * Meta information extracted from the WSDL
 * - nillable: true
 * - type: tns:ArrayOfCrm.DuplicationCheckRule
 * @subpackage Arrays
 */
class ArrayOfCrm_DuplicationCheckRule extends AbstractStructArrayBase
{
    /**
     * The Crm_DuplicationCheckRule
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var \patest\StructType\Crm_DuplicationCheckRule[]
     */
    public $Crm_DuplicationCheckRule;
    /**
     * Constructor method for ArrayOfCrm.DuplicationCheckRule
     * @uses ArrayOfCrm_DuplicationCheckRule::setCrm_DuplicationCheckRule()
     * @param \patest\StructType\Crm_DuplicationCheckRule[] $crm_DuplicationCheckRule
     */
    public function __construct(array $crm_DuplicationCheckRule = array())
    {
        $this
            ->setCrm_DuplicationCheckRule($crm_DuplicationCheckRule);
    }
    /**
     * Get Crm_DuplicationCheckRule value
     * An additional test has been added (isset) before returning the property value as
     * this property may have been unset before, due to the fact that this property is
     * removable from the request (nillable=true+minOccurs=0)
     * @return \patest\StructType\Crm_DuplicationCheckRule[]|null
     */
    public function getCrm_DuplicationCheckRule()
    {
        return isset($this->{'Crm.DuplicationCheckRule'}) ? $this->{'Crm.DuplicationCheckRule'} : null;
    }
    /**
     * This method is responsible for validating the values passed to the setCrm_DuplicationCheckRule method
     * This method is willingly generated in order to preserve the one-line inline validation within the setCrm_DuplicationCheckRule method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateCrm_DuplicationCheckRuleForArrayConstraintsFromSetCrm_DuplicationCheckRule(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem) {
            // validation for constraint: itemType
            if (!$arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem instanceof \patest\StructType\Crm_DuplicationCheckRule) {
                $invalidValues[] = is_object($arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem) ? get_class($arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem) : sprintf('%s(%s)', gettype($arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem), var_export($arrayOfCrm_DuplicationCheckRuleCrm_DuplicationCheckRuleItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Crm_DuplicationCheckRule property can only contain items of type \patest\StructType\Crm_DuplicationCheckRule, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set Crm_DuplicationCheckRule value
     * This property is removable from request (nillable=true+minOccurs=0), therefore
     * if the value assigned to this property is null, it is removed from this object
     * @throws \InvalidArgumentException
     * @param \patest\StructType\Crm_DuplicationCheckRule[] $crm_DuplicationCheckRule
     * @return \patest\ArrayType\ArrayOfCrm_DuplicationCheckRule
     */
    public function setCrm_DuplicationCheckRule(array $crm_DuplicationCheckRule = array())
    {
        // validation for constraint: array
        if ('' !== ($crm_DuplicationCheckRuleArrayErrorMessage = self::validateCrm_DuplicationCheckRuleForArrayConstraintsFromSetCrm_DuplicationCheckRule($crm_DuplicationCheckRule))) {
            throw new \InvalidArgumentException($crm_DuplicationCheckRuleArrayErrorMessage, __LINE__);
        }
        if (is_null($crm_DuplicationCheckRule) || (is_array($crm_DuplicationCheckRule) && empty($crm_DuplicationCheckRule))) {
            unset($this->Crm_DuplicationCheckRule, $this->{'Crm.DuplicationCheckRule'});
        } else {
            $this->Crm_DuplicationCheckRule = $this->{'Crm.DuplicationCheckRule'} = $crm_DuplicationCheckRule;
        }
        return $this;
    }
    /**
     * Add item to Crm_DuplicationCheckRule value
     * @throws \InvalidArgumentException
     * @param \patest\StructType\Crm_DuplicationCheckRule $item
     * @return \patest\ArrayType\ArrayOfCrm_DuplicationCheckRule
     */
    public function addToCrm_DuplicationCheckRule(\patest\StructType\Crm_DuplicationCheckRule $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \patest\StructType\Crm_DuplicationCheckRule) {
            throw new \InvalidArgumentException(sprintf('The Crm_DuplicationCheckRule property can only contain items of type \patest\StructType\Crm_DuplicationCheckRule, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Crm_DuplicationCheckRule[] = $this->{'Crm.DuplicationCheckRule'}[] = $item;
        return $this;
    }
    /**
     * Returns the current element
     * @see AbstractStructArrayBase::current()
     * @return \patest\StructType\Crm_DuplicationCheckRule|null
     */
    public function current()
    {
        return parent::current();
    }
    /**
     * Returns the indexed element
     * @see AbstractStructArrayBase::item()
     * @param int $index
     * @return \patest\StructType\Crm_DuplicationCheckRule|null
     */
    public function item($index)
    {
        return parent::item($index);
    }
    /**
     * Returns the first element
     * @see AbstractStructArrayBase::first()
     * @return \patest\StructType\Crm_DuplicationCheckRule|null
     */
    public function first()
    {
        return parent::first();
    }
    /**
     * Returns the last element
     * @see AbstractStructArrayBase::last()
     * @return \patest\StructType\Crm_DuplicationCheckRule|null
     */
    public function last()
    {
        return parent::last();
    }
    /**
     * Returns the element at the offset
     * @see AbstractStructArrayBase::offsetGet()
     * @param int $offset
     * @return \patest\StructType\Crm_DuplicationCheckRule|null
     */
    public function offsetGet($offset)
    {
        return parent::offsetGet($offset);
    }
    /**
     * Returns the attribute name
     * @see AbstractStructArrayBase::getAttributeName()
     * @return string Crm.DuplicationCheckRule
     */
    public function getAttributeName()
    {
        return 'Crm.DuplicationCheckRule';
    }
}
