<?php

namespace patest\StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for SetNullInstructions StructType
 * Meta information extracted from the WSDL
 * - nillable: true
 * - type: tns:SetNullInstructions
 * @subpackage Structs
 */
class SetNullInstructions extends AbstractStructBase
{
    /**
     * The Property
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var string[]
     */
    public $Property;
    /**
     * Constructor method for SetNullInstructions
     * @uses SetNullInstructions::setProperty()
     * @param string[] $property
     */
    public function __construct(array $property = array())
    {
        $this
            ->setProperty($property);
    }
    /**
     * Get Property value
     * An additional test has been added (isset) before returning the property value as
     * this property may have been unset before, due to the fact that this property is
     * removable from the request (nillable=true+minOccurs=0)
     * @return string[]|null
     */
    public function getProperty()
    {
        return isset($this->Property) ? $this->Property : null;
    }
    /**
     * This method is responsible for validating the values passed to the setProperty method
     * This method is willingly generated in order to preserve the one-line inline validation within the setProperty method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validatePropertyForArrayConstraintsFromSetProperty(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $setNullInstructionsPropertyItem) {
            // validation for constraint: itemType
            if (!is_string($setNullInstructionsPropertyItem)) {
                $invalidValues[] = is_object($setNullInstructionsPropertyItem) ? get_class($setNullInstructionsPropertyItem) : sprintf('%s(%s)', gettype($setNullInstructionsPropertyItem), var_export($setNullInstructionsPropertyItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Property property can only contain items of type string, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set Property value
     * This property is removable from request (nillable=true+minOccurs=0), therefore
     * if the value assigned to this property is null, it is removed from this object
     * @throws \InvalidArgumentException
     * @param string[] $property
     * @return \patest\StructType\SetNullInstructions
     */
    public function setProperty(array $property = array())
    {
        // validation for constraint: array
        if ('' !== ($propertyArrayErrorMessage = self::validatePropertyForArrayConstraintsFromSetProperty($property))) {
            throw new \InvalidArgumentException($propertyArrayErrorMessage, __LINE__);
        }
        if (is_null($property) || (is_array($property) && empty($property))) {
            unset($this->Property);
        } else {
            $this->Property = $property;
        }
        return $this;
    }
    /**
     * Add item to Property value
     * @throws \InvalidArgumentException
     * @param string $item
     * @return \patest\StructType\SetNullInstructions
     */
    public function addToProperty($item)
    {
        // validation for constraint: itemType
        if (!is_string($item)) {
            throw new \InvalidArgumentException(sprintf('The Property property can only contain items of type string, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Property[] = $item;
        return $this;
    }
}
