<?php

namespace Speedex\SpeedexArray;

use \WsdlToPhp\PackageBase\AbstractStructArrayBase;

/**
 * This class stands for ArrayOfPickupCheckpoint SpeedexArray
 * @package Speedex
 * @subpackage Arrays
 */
class SpeedexArrayOfPickupCheckpoint extends AbstractStructArrayBase
{
    /**
     * The PickupCheckpoint
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * - nillable: true
     * @var \Speedex\SpeedexStruct\SpeedexPickupCheckpoint[]
     */
    public $PickupCheckpoint;
    /**
     * Constructor method for ArrayOfPickupCheckpoint
     * @uses SpeedexArrayOfPickupCheckpoint::setPickupCheckpoint()
     * @param \Speedex\SpeedexStruct\SpeedexPickupCheckpoint[] $pickupCheckpoint
     */
    public function __construct(array $pickupCheckpoint = array())
    {
        $this
            ->setPickupCheckpoint($pickupCheckpoint);
    }
    /**
     * Get PickupCheckpoint 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 \Speedex\SpeedexStruct\SpeedexPickupCheckpoint[]|null
     */
    public function getPickupCheckpoint()
    {
        return isset($this->PickupCheckpoint) ? $this->PickupCheckpoint : null;
    }
    /**
     * This method is responsible for validating the values passed to the setPickupCheckpoint method
     * This method is willingly generated in order to preserve the one-line inline validation within the setPickupCheckpoint method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validatePickupCheckpointForArrayConstraintsFromSetPickupCheckpoint(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $arrayOfPickupCheckpointPickupCheckpointItem) {
            // validation for constraint: itemType
            if (!$arrayOfPickupCheckpointPickupCheckpointItem instanceof \Speedex\SpeedexStruct\SpeedexPickupCheckpoint) {
                $invalidValues[] = is_object($arrayOfPickupCheckpointPickupCheckpointItem) ? get_class($arrayOfPickupCheckpointPickupCheckpointItem) : sprintf('%s(%s)', gettype($arrayOfPickupCheckpointPickupCheckpointItem), var_export($arrayOfPickupCheckpointPickupCheckpointItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The PickupCheckpoint property can only contain items of type \Speedex\SpeedexStruct\SpeedexPickupCheckpoint, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set PickupCheckpoint 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 \Speedex\SpeedexStruct\SpeedexPickupCheckpoint[] $pickupCheckpoint
     * @return \Speedex\SpeedexArray\SpeedexArrayOfPickupCheckpoint
     */
    public function setPickupCheckpoint(array $pickupCheckpoint = array())
    {
        // validation for constraint: array
        if ('' !== ($pickupCheckpointArrayErrorMessage = self::validatePickupCheckpointForArrayConstraintsFromSetPickupCheckpoint($pickupCheckpoint))) {
            throw new \InvalidArgumentException($pickupCheckpointArrayErrorMessage, __LINE__);
        }
        if (is_null($pickupCheckpoint) || (is_array($pickupCheckpoint) && empty($pickupCheckpoint))) {
            unset($this->PickupCheckpoint);
        } else {
            $this->PickupCheckpoint = $pickupCheckpoint;
        }
        return $this;
    }
    /**
     * Add item to PickupCheckpoint value
     * @throws \InvalidArgumentException
     * @param \Speedex\SpeedexStruct\SpeedexPickupCheckpoint $item
     * @return \Speedex\SpeedexArray\SpeedexArrayOfPickupCheckpoint
     */
    public function addToPickupCheckpoint(\Speedex\SpeedexStruct\SpeedexPickupCheckpoint $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \Speedex\SpeedexStruct\SpeedexPickupCheckpoint) {
            throw new \InvalidArgumentException(sprintf('The PickupCheckpoint property can only contain items of type \Speedex\SpeedexStruct\SpeedexPickupCheckpoint, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->PickupCheckpoint[] = $item;
        return $this;
    }
    /**
     * Returns the current element
     * @see AbstractStructArrayBase::current()
     * @return \Speedex\SpeedexStruct\SpeedexPickupCheckpoint|null
     */
    public function current()
    {
        return parent::current();
    }
    /**
     * Returns the indexed element
     * @see AbstractStructArrayBase::item()
     * @param int $index
     * @return \Speedex\SpeedexStruct\SpeedexPickupCheckpoint|null
     */
    public function item($index)
    {
        return parent::item($index);
    }
    /**
     * Returns the first element
     * @see AbstractStructArrayBase::first()
     * @return \Speedex\SpeedexStruct\SpeedexPickupCheckpoint|null
     */
    public function first()
    {
        return parent::first();
    }
    /**
     * Returns the last element
     * @see AbstractStructArrayBase::last()
     * @return \Speedex\SpeedexStruct\SpeedexPickupCheckpoint|null
     */
    public function last()
    {
        return parent::last();
    }
    /**
     * Returns the element at the offset
     * @see AbstractStructArrayBase::offsetGet()
     * @param int $offset
     * @return \Speedex\SpeedexStruct\SpeedexPickupCheckpoint|null
     */
    public function offsetGet($offset)
    {
        return parent::offsetGet($offset);
    }
    /**
     * Returns the attribute name
     * @see AbstractStructArrayBase::getAttributeName()
     * @return string PickupCheckpoint
     */
    public function getAttributeName()
    {
        return 'PickupCheckpoint';
    }
}
