<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for Registrant_SessionCollectionType StructType
 * @subpackage Structs
 * @author Drupal NetForum xWeb PHP SDK Generator
 * @version 1.0.0
 * @license GPL-2.0-or-later https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @see https://www.drupal.org/project/netforum
 * @generatedDate 2025-08-05
 * @generatedRelease Official
 * @generatedNetForumVersion 37
 */
#[\AllowDynamicProperties]
class Registrant_SessionCollectionType extends AbstractStructBase
{
    /**
     * The EventsRegistrantSession
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType[]
     */
    protected ?array $EventsRegistrantSession = null;
    /**
     * Constructor method for Registrant_SessionCollectionType
     * @uses Registrant_SessionCollectionType::setEventsRegistrantSession()
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType[] $eventsRegistrantSession
     */
    public function __construct(?array $eventsRegistrantSession = null)
    {
        $this
            ->setEventsRegistrantSession($eventsRegistrantSession);
    }
    /**
     * Get EventsRegistrantSession value
     * @return \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType[]
     */
    public function getEventsRegistrantSession(): ?array
    {
        return $this->EventsRegistrantSession;
    }
    /**
     * This method is responsible for validating the value(s) passed to the setEventsRegistrantSession method
     * This method is willingly generated in order to preserve the one-line inline validation within the setEventsRegistrantSession method
     * This has to validate that each item contained by the array match the itemType constraint
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateEventsRegistrantSessionForArrayConstraintFromSetEventsRegistrantSession(?array $values = []): string
    {
        if (!is_array($values)) {
            return '';
        }
        $message = '';
        $invalidValues = [];
        foreach ($values as $registrant_SessionCollectionTypeEventsRegistrantSessionItem) {
            // validation for constraint: itemType
            if (!$registrant_SessionCollectionTypeEventsRegistrantSessionItem instanceof \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType) {
                $invalidValues[] = is_object($registrant_SessionCollectionTypeEventsRegistrantSessionItem) ? get_class($registrant_SessionCollectionTypeEventsRegistrantSessionItem) : sprintf('%s(%s)', gettype($registrant_SessionCollectionTypeEventsRegistrantSessionItem), var_export($registrant_SessionCollectionTypeEventsRegistrantSessionItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The EventsRegistrantSession property can only contain items of type \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        
        return $message;
    }
    /**
     * Set EventsRegistrantSession value
     * @throws InvalidArgumentException
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType[] $eventsRegistrantSession
     * @return \Drupal\netforum\xWeb\Generated\StructType\Registrant_SessionCollectionType
     */
    public function setEventsRegistrantSession(?array $eventsRegistrantSession = null): self
    {
        // validation for constraint: array
        if ('' !== ($eventsRegistrantSessionArrayErrorMessage = self::validateEventsRegistrantSessionForArrayConstraintFromSetEventsRegistrantSession($eventsRegistrantSession))) {
            throw new InvalidArgumentException($eventsRegistrantSessionArrayErrorMessage, __LINE__);
        }
        $this->EventsRegistrantSession = $eventsRegistrantSession;
        
        return $this;
    }
    /**
     * Add item to EventsRegistrantSession value
     * @throws InvalidArgumentException
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType $item
     * @return \Drupal\netforum\xWeb\Generated\StructType\Registrant_SessionCollectionType
     */
    public function addToEventsRegistrantSession(\Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType $item): self
    {
        // validation for constraint: itemType
        if (!$item instanceof \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType) {
            throw new InvalidArgumentException(sprintf('The EventsRegistrantSession property can only contain items of type \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantSessionType, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->EventsRegistrantSession[] = $item;
        
        return $this;
    }
}
