<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for SearchColumnCustomFieldList StructType
 * @subpackage Structs
 */
class SearchColumnCustomFieldList extends AbstractStructBase
{
    /**
     * The customField
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \StructType\SearchColumnCustomField[]
     */
    public $customField;
    /**
     * Constructor method for SearchColumnCustomFieldList
     * @uses SearchColumnCustomFieldList::setCustomField()
     * @param \StructType\SearchColumnCustomField[] $customField
     */
    public function __construct(array $customField = array())
    {
        $this
            ->setCustomField($customField);
    }
    /**
     * Get customField value
     * @return \StructType\SearchColumnCustomField[]|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 $searchColumnCustomFieldListCustomFieldItem) {
            // validation for constraint: itemType
            if (!$searchColumnCustomFieldListCustomFieldItem instanceof \StructType\SearchColumnCustomField) {
                $invalidValues[] = is_object($searchColumnCustomFieldListCustomFieldItem) ? get_class($searchColumnCustomFieldListCustomFieldItem) : sprintf('%s(%s)', gettype($searchColumnCustomFieldListCustomFieldItem), var_export($searchColumnCustomFieldListCustomFieldItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The customField property can only contain items of type \StructType\SearchColumnCustomField, %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\SearchColumnCustomField[] $customField
     * @return \StructType\SearchColumnCustomFieldList
     */
    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\SearchColumnCustomField $item
     * @return \StructType\SearchColumnCustomFieldList
     */
    public function addToCustomField(\StructType\SearchColumnCustomField $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \StructType\SearchColumnCustomField) {
            throw new \InvalidArgumentException(sprintf('The customField property can only contain items of type \StructType\SearchColumnCustomField, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->customField[] = $item;
        return $this;
    }
}
