<?php

namespace patest\StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for RecordSetOfSales.PriceListBasePrice StructType
 * @subpackage Structs
 */
class RecordSetOfSales_PriceListBasePrice extends AbstractStructBase
{
    /**
     * The Record
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var \patest\StructType\Sales_PriceListBasePrice[]
     */
    public $Record;
    /**
     * Constructor method for RecordSetOfSales.PriceListBasePrice
     * @uses RecordSetOfSales_PriceListBasePrice::setRecord()
     * @param \patest\StructType\Sales_PriceListBasePrice[] $record
     */
    public function __construct(array $record = array())
    {
        $this
            ->setRecord($record);
    }
    /**
     * Get Record value
     * An additional test has been added (isset) before returning the property value as
     * this property may have been unset before, due to the fact that this property is
     * removable from the request (nillable=true+minOccurs=0)
     * @return \patest\StructType\Sales_PriceListBasePrice[]|null
     */
    public function getRecord()
    {
        return isset($this->Record) ? $this->Record : null;
    }
    /**
     * This method is responsible for validating the values passed to the setRecord method
     * This method is willingly generated in order to preserve the one-line inline validation within the setRecord method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateRecordForArrayConstraintsFromSetRecord(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $recordSetOfSales_PriceListBasePriceRecordItem) {
            // validation for constraint: itemType
            if (!$recordSetOfSales_PriceListBasePriceRecordItem instanceof \patest\StructType\Sales_PriceListBasePrice) {
                $invalidValues[] = is_object($recordSetOfSales_PriceListBasePriceRecordItem) ? get_class($recordSetOfSales_PriceListBasePriceRecordItem) : sprintf('%s(%s)', gettype($recordSetOfSales_PriceListBasePriceRecordItem), var_export($recordSetOfSales_PriceListBasePriceRecordItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Record property can only contain items of type \patest\StructType\Sales_PriceListBasePrice, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set Record value
     * This property is removable from request (nillable=true+minOccurs=0), therefore
     * if the value assigned to this property is null, it is removed from this object
     * @throws \InvalidArgumentException
     * @param \patest\StructType\Sales_PriceListBasePrice[] $record
     * @return \patest\StructType\RecordSetOfSales_PriceListBasePrice
     */
    public function setRecord(array $record = array())
    {
        // validation for constraint: array
        if ('' !== ($recordArrayErrorMessage = self::validateRecordForArrayConstraintsFromSetRecord($record))) {
            throw new \InvalidArgumentException($recordArrayErrorMessage, __LINE__);
        }
        if (is_null($record) || (is_array($record) && empty($record))) {
            unset($this->Record);
        } else {
            $this->Record = $record;
        }
        return $this;
    }
    /**
     * Add item to Record value
     * @throws \InvalidArgumentException
     * @param \patest\StructType\Sales_PriceListBasePrice $item
     * @return \patest\StructType\RecordSetOfSales_PriceListBasePrice
     */
    public function addToRecord(\patest\StructType\Sales_PriceListBasePrice $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \patest\StructType\Sales_PriceListBasePrice) {
            throw new \InvalidArgumentException(sprintf('The Record property can only contain items of type \patest\StructType\Sales_PriceListBasePrice, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Record[] = $item;
        return $this;
    }
}
