<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

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