<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

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