<?php

namespace patest\StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for RecordSetOfPrinting.AuxDataItem.ClientContactDetail
 * StructType
 * @subpackage Structs
 */
class RecordSetOfPrinting_AuxDataItem_ClientContactDetail extends AbstractStructBase
{
    /**
     * The Record
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var \patest\StructType\Printing_AuxDataItem_ClientContactDetail[]
     */
    public $Record;
    /**
     * Constructor method for RecordSetOfPrinting.AuxDataItem.ClientContactDetail
     * @uses RecordSetOfPrinting_AuxDataItem_ClientContactDetail::setRecord()
     * @param \patest\StructType\Printing_AuxDataItem_ClientContactDetail[] $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\Printing_AuxDataItem_ClientContactDetail[]|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 $recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem) {
            // validation for constraint: itemType
            if (!$recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem instanceof \patest\StructType\Printing_AuxDataItem_ClientContactDetail) {
                $invalidValues[] = is_object($recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem) ? get_class($recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem) : sprintf('%s(%s)', gettype($recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem), var_export($recordSetOfPrinting_AuxDataItem_ClientContactDetailRecordItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Record property can only contain items of type \patest\StructType\Printing_AuxDataItem_ClientContactDetail, %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\Printing_AuxDataItem_ClientContactDetail[] $record
     * @return \patest\StructType\RecordSetOfPrinting_AuxDataItem_ClientContactDetail
     */
    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\Printing_AuxDataItem_ClientContactDetail $item
     * @return \patest\StructType\RecordSetOfPrinting_AuxDataItem_ClientContactDetail
     */
    public function addToRecord(\patest\StructType\Printing_AuxDataItem_ClientContactDetail $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \patest\StructType\Printing_AuxDataItem_ClientContactDetail) {
            throw new \InvalidArgumentException(sprintf('The Record property can only contain items of type \patest\StructType\Printing_AuxDataItem_ClientContactDetail, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Record[] = $item;
        return $this;
    }
}
