<?php

namespace patest\StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

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