<?php

declare(strict_types=1);

namespace Drupal\netforum\xWeb\Generated\StructType;

use InvalidArgumentException;
use WsdlToPhp\PackageBase\AbstractStructBase;

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