<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for RegistrantCollectionType 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 RegistrantCollectionType extends AbstractStructBase
{
    /**
     * The EventsRegistrant
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType[]
     */
    protected ?array $EventsRegistrant = null;
    /**
     * Constructor method for RegistrantCollectionType
     * @uses RegistrantCollectionType::setEventsRegistrant()
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType[] $eventsRegistrant
     */
    public function __construct(?array $eventsRegistrant = null)
    {
        $this
            ->setEventsRegistrant($eventsRegistrant);
    }
    /**
     * Get EventsRegistrant value
     * @return \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType[]
     */
    public function getEventsRegistrant(): ?array
    {
        return $this->EventsRegistrant;
    }
    /**
     * This method is responsible for validating the value(s) passed to the setEventsRegistrant method
     * This method is willingly generated in order to preserve the one-line inline validation within the setEventsRegistrant 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 validateEventsRegistrantForArrayConstraintFromSetEventsRegistrant(?array $values = []): string
    {
        if (!is_array($values)) {
            return '';
        }
        $message = '';
        $invalidValues = [];
        foreach ($values as $registrantCollectionTypeEventsRegistrantItem) {
            // validation for constraint: itemType
            if (!$registrantCollectionTypeEventsRegistrantItem instanceof \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType) {
                $invalidValues[] = is_object($registrantCollectionTypeEventsRegistrantItem) ? get_class($registrantCollectionTypeEventsRegistrantItem) : sprintf('%s(%s)', gettype($registrantCollectionTypeEventsRegistrantItem), var_export($registrantCollectionTypeEventsRegistrantItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The EventsRegistrant property can only contain items of type \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        
        return $message;
    }
    /**
     * Set EventsRegistrant value
     * @throws InvalidArgumentException
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType[] $eventsRegistrant
     * @return \Drupal\netforum\xWeb\Generated\StructType\RegistrantCollectionType
     */
    public function setEventsRegistrant(?array $eventsRegistrant = null): self
    {
        // validation for constraint: array
        if ('' !== ($eventsRegistrantArrayErrorMessage = self::validateEventsRegistrantForArrayConstraintFromSetEventsRegistrant($eventsRegistrant))) {
            throw new InvalidArgumentException($eventsRegistrantArrayErrorMessage, __LINE__);
        }
        $this->EventsRegistrant = $eventsRegistrant;
        
        return $this;
    }
    /**
     * Add item to EventsRegistrant value
     * @throws InvalidArgumentException
     * @param \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType $item
     * @return \Drupal\netforum\xWeb\Generated\StructType\RegistrantCollectionType
     */
    public function addToEventsRegistrant(\Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType $item): self
    {
        // validation for constraint: itemType
        if (!$item instanceof \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType) {
            throw new InvalidArgumentException(sprintf('The EventsRegistrant property can only contain items of type \Drupal\netforum\xWeb\Generated\StructType\EventsRegistrantType, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->EventsRegistrant[] = $item;
        
        return $this;
    }
}
