<?php

namespace Cocorico\EdnBundle\Wsdl;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for getCarriersResponse StructType
 * @subpackage Structs
 */
class GetCarriersResponse extends AbstractStructBase
{
    /**
     * The carriers
     * Meta information extracted from the WSDL
     * - arrayType: tns:carrierType[]
     * - base: SOAP-ENC:Array
     * - maxOccurs: 1
     * - minOccurs: 1
     * - ref: SOAP-ENC:arrayType
     * @var \Cocorico\EdnBundle\Wsdl\CarrierType[]
     */
    public $carriers;
    /**
     * Constructor method for getCarriersResponse
     * @uses GetCarriersResponse::setCarriers()
     * @param \Cocorico\EdnBundle\Wsdl\CarrierType[] $carriers
     */
    public function __construct(array $carriers = array())
    {
        $this
            ->setCarriers($carriers);
    }
    /**
     * Get carriers value
     * @return \Cocorico\EdnBundle\Wsdl\CarrierType[]
     */
    public function getCarriers()
    {
        return $this->carriers;
    }
    /**
     * This method is responsible for validating the values passed to the setCarriers method
     * This method is willingly generated in order to preserve the one-line inline validation within the setCarriers method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateCarriersForArrayConstraintsFromSetCarriers(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $getCarriersResponseCarriersItem) {
            // validation for constraint: itemType
            if (!$getCarriersResponseCarriersItem instanceof \Cocorico\EdnBundle\Wsdl\CarrierType) {
                $invalidValues[] = is_object($getCarriersResponseCarriersItem) ? get_class($getCarriersResponseCarriersItem) : sprintf('%s(%s)', gettype($getCarriersResponseCarriersItem), var_export($getCarriersResponseCarriersItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The carriers property can only contain items of type \Cocorico\EdnBundle\Wsdl\CarrierType, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set carriers value
     * @throws \InvalidArgumentException
     * @param \Cocorico\EdnBundle\Wsdl\CarrierType[] $carriers
     * @return \Cocorico\EdnBundle\Wsdl\GetCarriersResponse
     */
    public function setCarriers(array $carriers = array())
    {
        // validation for constraint: array
        if ('' !== ($carriersArrayErrorMessage = self::validateCarriersForArrayConstraintsFromSetCarriers($carriers))) {
            throw new \InvalidArgumentException($carriersArrayErrorMessage, __LINE__);
        }
        // validation for constraint: maxOccurs(1)
        if (is_array($carriers) && count($carriers) > 1) {
            throw new \InvalidArgumentException(sprintf('Invalid count of %s, the number of elements contained by the property must be less than or equal to 1', count($carriers)), __LINE__);
        }
        $this->carriers = $carriers;
        return $this;
    }
    /**
     * Add item to carriers value
     * @throws \InvalidArgumentException
     * @param \Cocorico\EdnBundle\Wsdl\CarrierType $item
     * @return \Cocorico\EdnBundle\Wsdl\GetCarriersResponse
     */
    public function addToCarriers(\Cocorico\EdnBundle\Wsdl\CarrierType $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \Cocorico\EdnBundle\Wsdl\CarrierType) {
            throw new \InvalidArgumentException(sprintf('The carriers property can only contain items of type \Cocorico\EdnBundle\Wsdl\CarrierType, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        // validation for constraint: maxOccurs(1)
        if (is_array($this->carriers) && count($this->carriers) >= 1) {
            throw new \InvalidArgumentException(sprintf('You can\'t add anymore element to this property that already contains %s elements, the number of elements contained by the property must be less than or equal to 1', count($this->carriers)), __LINE__);
        }
        $this->carriers[] = $item;
        return $this;
    }
    /**
     * Method called when an object has been exported with var_export() functions
     * It allows to return an object instantiated with the values
     * @see AbstractStructBase::__set_state()
     * @uses AbstractStructBase::__set_state()
     * @param array $array the exported values
     * @return \Cocorico\EdnBundle\Wsdl\GetCarriersResponse
     */
    public static function __set_state(array $array)
    {
        return parent::__set_state($array);
    }
    /**
     * Method returning the class name
     * @return string __CLASS__
     */
    public function __toString()
    {
        return __CLASS__;
    }
}
