<?php
use \WsdlToPhp\PackageBase\AbstractStructArrayBase;

/**
 * This class stands for ArrayOfRichiestaCartellino_Motivo ArrayType
 * Meta information extracted from the WSDL
 * - nillable: true
 * - type: tns:ArrayOfRichiestaCartellino_Motivo
 * @subpackage Arrays
 */
class ArrayOfRichiestaCartellino_Motivo extends AbstractStructArrayBase
{
    /**
     * The RichiestaCartellino_Motivo
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var RichiestaCartellino_Motivo[]
     */
    public $RichiestaCartellino_Motivo;
    /**
     * Constructor method for ArrayOfRichiestaCartellino_Motivo
     * @uses ArrayOfRichiestaCartellino_Motivo::setRichiestaCartellino_Motivo()
     * @param RichiestaCartellino_Motivo[] $richiestaCartellino_Motivo
     */
    public function __construct(array $richiestaCartellino_Motivo = array())
    {
        $this
            ->setRichiestaCartellino_Motivo($richiestaCartellino_Motivo);
    }
    /**
     * Get RichiestaCartellino_Motivo 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 RichiestaCartellino_Motivo[]|null
     */
    public function getRichiestaCartellino_Motivo()
    {
        return isset($this->RichiestaCartellino_Motivo) ? $this->RichiestaCartellino_Motivo : null;
    }
    /**
     * This method is responsible for validating the values passed to the setRichiestaCartellino_Motivo method
     * This method is willingly generated in order to preserve the one-line inline validation within the setRichiestaCartellino_Motivo method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateRichiestaCartellino_MotivoForArrayConstraintsFromSetRichiestaCartellino_Motivo(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem) {
            // validation for constraint: itemType
            if (!$arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem instanceof RichiestaCartellino_Motivo) {
                $invalidValues[] = is_object($arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem) ? get_class($arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem) : sprintf('%s(%s)', gettype($arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem), var_export($arrayOfRichiestaCartellino_MotivoRichiestaCartellino_MotivoItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The RichiestaCartellino_Motivo property can only contain items of type RichiestaCartellino_Motivo, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set RichiestaCartellino_Motivo 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 RichiestaCartellino_Motivo[] $richiestaCartellino_Motivo
     * @return ArrayOfRichiestaCartellino_Motivo
     */
    public function setRichiestaCartellino_Motivo(array $richiestaCartellino_Motivo = array())
    {
        // validation for constraint: array
        if ('' !== ($richiestaCartellino_MotivoArrayErrorMessage = self::validateRichiestaCartellino_MotivoForArrayConstraintsFromSetRichiestaCartellino_Motivo($richiestaCartellino_Motivo))) {
            throw new \InvalidArgumentException($richiestaCartellino_MotivoArrayErrorMessage, __LINE__);
        }
        if (is_null($richiestaCartellino_Motivo) || (is_array($richiestaCartellino_Motivo) && empty($richiestaCartellino_Motivo))) {
            unset($this->RichiestaCartellino_Motivo);
        } else {
            $this->RichiestaCartellino_Motivo = $richiestaCartellino_Motivo;
        }
        return $this;
    }
    /**
     * Add item to RichiestaCartellino_Motivo value
     * @throws \InvalidArgumentException
     * @param RichiestaCartellino_Motivo $item
     * @return ArrayOfRichiestaCartellino_Motivo
     */
    public function addToRichiestaCartellino_Motivo(RichiestaCartellino_Motivo $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof RichiestaCartellino_Motivo) {
            throw new \InvalidArgumentException(sprintf('The RichiestaCartellino_Motivo property can only contain items of type RichiestaCartellino_Motivo, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->RichiestaCartellino_Motivo[] = $item;
        return $this;
    }
    /**
     * Returns the current element
     * @see AbstractStructArrayBase::current()
     * @return RichiestaCartellino_Motivo|null
     */
    public function current()
    {
        return parent::current();
    }
    /**
     * Returns the indexed element
     * @see AbstractStructArrayBase::item()
     * @param int $index
     * @return RichiestaCartellino_Motivo|null
     */
    public function item($index)
    {
        return parent::item($index);
    }
    /**
     * Returns the first element
     * @see AbstractStructArrayBase::first()
     * @return RichiestaCartellino_Motivo|null
     */
    public function first()
    {
        return parent::first();
    }
    /**
     * Returns the last element
     * @see AbstractStructArrayBase::last()
     * @return RichiestaCartellino_Motivo|null
     */
    public function last()
    {
        return parent::last();
    }
    /**
     * Returns the element at the offset
     * @see AbstractStructArrayBase::offsetGet()
     * @param int $offset
     * @return RichiestaCartellino_Motivo|null
     */
    public function offsetGet($offset)
    {
        return parent::offsetGet($offset);
    }
    /**
     * Returns the attribute name
     * @see AbstractStructArrayBase::getAttributeName()
     * @return string RichiestaCartellino_Motivo
     */
    public function getAttributeName()
    {
        return 'RichiestaCartellino_Motivo';
    }
}
