<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for InventoryCostRevaluationCostComponentList StructType
 * @subpackage Structs
 */
class InventoryCostRevaluationCostComponentList extends AbstractStructBase
{
    /**
     * The costComponent
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \StructType\InventoryCostRevaluationCostComponent[]
     */
    public $costComponent;
    /**
     * The replaceAll
     * Meta information extracted from the WSDL
     * - default: true
     * @var bool
     */
    public $replaceAll;
    /**
     * Constructor method for InventoryCostRevaluationCostComponentList
     * @uses InventoryCostRevaluationCostComponentList::setCostComponent()
     * @uses InventoryCostRevaluationCostComponentList::setReplaceAll()
     * @param \StructType\InventoryCostRevaluationCostComponent[] $costComponent
     * @param bool $replaceAll
     */
    public function __construct(array $costComponent = array(), $replaceAll = true)
    {
        $this
            ->setCostComponent($costComponent)
            ->setReplaceAll($replaceAll);
    }
    /**
     * Get costComponent value
     * @return \StructType\InventoryCostRevaluationCostComponent[]|null
     */
    public function getCostComponent()
    {
        return $this->costComponent;
    }
    /**
     * This method is responsible for validating the values passed to the setCostComponent method
     * This method is willingly generated in order to preserve the one-line inline validation within the setCostComponent method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateCostComponentForArrayConstraintsFromSetCostComponent(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $inventoryCostRevaluationCostComponentListCostComponentItem) {
            // validation for constraint: itemType
            if (!$inventoryCostRevaluationCostComponentListCostComponentItem instanceof \StructType\InventoryCostRevaluationCostComponent) {
                $invalidValues[] = is_object($inventoryCostRevaluationCostComponentListCostComponentItem) ? get_class($inventoryCostRevaluationCostComponentListCostComponentItem) : sprintf('%s(%s)', gettype($inventoryCostRevaluationCostComponentListCostComponentItem), var_export($inventoryCostRevaluationCostComponentListCostComponentItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The costComponent property can only contain items of type \StructType\InventoryCostRevaluationCostComponent, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set costComponent value
     * @throws \InvalidArgumentException
     * @param \StructType\InventoryCostRevaluationCostComponent[] $costComponent
     * @return \StructType\InventoryCostRevaluationCostComponentList
     */
    public function setCostComponent(array $costComponent = array())
    {
        // validation for constraint: array
        if ('' !== ($costComponentArrayErrorMessage = self::validateCostComponentForArrayConstraintsFromSetCostComponent($costComponent))) {
            throw new \InvalidArgumentException($costComponentArrayErrorMessage, __LINE__);
        }
        $this->costComponent = $costComponent;
        return $this;
    }
    /**
     * Add item to costComponent value
     * @throws \InvalidArgumentException
     * @param \StructType\InventoryCostRevaluationCostComponent $item
     * @return \StructType\InventoryCostRevaluationCostComponentList
     */
    public function addToCostComponent(\StructType\InventoryCostRevaluationCostComponent $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \StructType\InventoryCostRevaluationCostComponent) {
            throw new \InvalidArgumentException(sprintf('The costComponent property can only contain items of type \StructType\InventoryCostRevaluationCostComponent, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->costComponent[] = $item;
        return $this;
    }
    /**
     * Get replaceAll value
     * @return bool|null
     */
    public function getReplaceAll()
    {
        return $this->replaceAll;
    }
    /**
     * Set replaceAll value
     * @param bool $replaceAll
     * @return \StructType\InventoryCostRevaluationCostComponentList
     */
    public function setReplaceAll($replaceAll = true)
    {
        // validation for constraint: boolean
        if (!is_null($replaceAll) && !is_bool($replaceAll)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a bool, %s given', var_export($replaceAll, true), gettype($replaceAll)), __LINE__);
        }
        $this->replaceAll = $replaceAll;
        return $this;
    }
}
