<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for InitializeRefList StructType
 * @subpackage Structs
 */
class InitializeRefList extends AbstractStructBase
{
    /**
     * The initializeRef
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \StructType\InitializeRef[]
     */
    public $initializeRef;
    /**
     * Constructor method for InitializeRefList
     * @uses InitializeRefList::setInitializeRef()
     * @param \StructType\InitializeRef[] $initializeRef
     */
    public function __construct(array $initializeRef = array())
    {
        $this
            ->setInitializeRef($initializeRef);
    }
    /**
     * Get initializeRef value
     * @return \StructType\InitializeRef[]|null
     */
    public function getInitializeRef()
    {
        return $this->initializeRef;
    }
    /**
     * This method is responsible for validating the values passed to the setInitializeRef method
     * This method is willingly generated in order to preserve the one-line inline validation within the setInitializeRef method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateInitializeRefForArrayConstraintsFromSetInitializeRef(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $initializeRefListInitializeRefItem) {
            // validation for constraint: itemType
            if (!$initializeRefListInitializeRefItem instanceof \StructType\InitializeRef) {
                $invalidValues[] = is_object($initializeRefListInitializeRefItem) ? get_class($initializeRefListInitializeRefItem) : sprintf('%s(%s)', gettype($initializeRefListInitializeRefItem), var_export($initializeRefListInitializeRefItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The initializeRef property can only contain items of type \StructType\InitializeRef, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set initializeRef value
     * @throws \InvalidArgumentException
     * @param \StructType\InitializeRef[] $initializeRef
     * @return \StructType\InitializeRefList
     */
    public function setInitializeRef(array $initializeRef = array())
    {
        // validation for constraint: array
        if ('' !== ($initializeRefArrayErrorMessage = self::validateInitializeRefForArrayConstraintsFromSetInitializeRef($initializeRef))) {
            throw new \InvalidArgumentException($initializeRefArrayErrorMessage, __LINE__);
        }
        $this->initializeRef = $initializeRef;
        return $this;
    }
    /**
     * Add item to initializeRef value
     * @throws \InvalidArgumentException
     * @param \StructType\InitializeRef $item
     * @return \StructType\InitializeRefList
     */
    public function addToInitializeRef(\StructType\InitializeRef $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \StructType\InitializeRef) {
            throw new \InvalidArgumentException(sprintf('The initializeRef property can only contain items of type \StructType\InitializeRef, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->initializeRef[] = $item;
        return $this;
    }
}
