<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for JPSOAP_CountryOfResidence StructType
 * @subpackage Structs
 */
class JPSOAP_CountryOfResidence extends AbstractStructBase
{
    /**
     * The Country
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \StructType\JP_Country[]
     */
    public $Country;
    /**
     * The Allowed
     * @var bool
     */
    public $Allowed;
    /**
     * Constructor method for JPSOAP_CountryOfResidence
     * @uses JPSOAP_CountryOfResidence::setCountry()
     * @uses JPSOAP_CountryOfResidence::setAllowed()
     * @param \StructType\JP_Country[] $country
     * @param bool $allowed
     */
    public function __construct(array $country = array(), $allowed = null)
    {
        $this
            ->setCountry($country)
            ->setAllowed($allowed);
    }
    /**
     * Get Country value
     * @return \StructType\JP_Country[]|null
     */
    public function getCountry()
    {
        return $this->Country;
    }
    /**
     * This method is responsible for validating the values passed to the setCountry method
     * This method is willingly generated in order to preserve the one-line inline validation within the setCountry method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateCountryForArrayConstraintsFromSetCountry(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $jPSOAP_CountryOfResidenceCountryItem) {
            // validation for constraint: itemType
            if (!$jPSOAP_CountryOfResidenceCountryItem instanceof \StructType\JP_Country) {
                $invalidValues[] = is_object($jPSOAP_CountryOfResidenceCountryItem) ? get_class($jPSOAP_CountryOfResidenceCountryItem) : sprintf('%s(%s)', gettype($jPSOAP_CountryOfResidenceCountryItem), var_export($jPSOAP_CountryOfResidenceCountryItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Country property can only contain items of type \StructType\JP_Country, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set Country value
     * @throws \InvalidArgumentException
     * @param \StructType\JP_Country[] $country
     * @return \StructType\JPSOAP_CountryOfResidence
     */
    public function setCountry(array $country = array())
    {
        // validation for constraint: array
        if ('' !== ($countryArrayErrorMessage = self::validateCountryForArrayConstraintsFromSetCountry($country))) {
            throw new \InvalidArgumentException($countryArrayErrorMessage, __LINE__);
        }
        $this->Country = $country;
        return $this;
    }
    /**
     * Add item to Country value
     * @throws \InvalidArgumentException
     * @param \StructType\JP_Country $item
     * @return \StructType\JPSOAP_CountryOfResidence
     */
    public function addToCountry(\StructType\JP_Country $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \StructType\JP_Country) {
            throw new \InvalidArgumentException(sprintf('The Country property can only contain items of type \StructType\JP_Country, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Country[] = $item;
        return $this;
    }
    /**
     * Get Allowed value
     * @return bool|null
     */
    public function getAllowed()
    {
        return $this->Allowed;
    }
    /**
     * Set Allowed value
     * @param bool $allowed
     * @return \StructType\JPSOAP_CountryOfResidence
     */
    public function setAllowed($allowed = null)
    {
        // validation for constraint: boolean
        if (!is_null($allowed) && !is_bool($allowed)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a bool, %s given', var_export($allowed, true), gettype($allowed)), __LINE__);
        }
        $this->Allowed = $allowed;
        return $this;
    }
}
