<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

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