<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

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