<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

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