<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for JP_CustomerChannels StructType
 * @subpackage Structs
 */
class JP_CustomerChannels extends AbstractStructBase
{
    /**
     * The Channel
     * Meta information extracted from the WSDL
     * - maxOccurs: unbounded
     * - minOccurs: 0
     * @var \StructType\JP_CustomerCodeElement[]
     */
    public $Channel;
    /**
     * The DefaultCode
     * @var string
     */
    public $DefaultCode;
    /**
     * Constructor method for JP_CustomerChannels
     * @uses JP_CustomerChannels::setChannel()
     * @uses JP_CustomerChannels::setDefaultCode()
     * @param \StructType\JP_CustomerCodeElement[] $channel
     * @param string $defaultCode
     */
    public function __construct(array $channel = array(), $defaultCode = null)
    {
        $this
            ->setChannel($channel)
            ->setDefaultCode($defaultCode);
    }
    /**
     * Get Channel value
     * @return \StructType\JP_CustomerCodeElement[]|null
     */
    public function getChannel()
    {
        return $this->Channel;
    }
    /**
     * This method is responsible for validating the values passed to the setChannel method
     * This method is willingly generated in order to preserve the one-line inline validation within the setChannel method
     * @param array $values
     * @return string A non-empty message if the values does not match the validation rules
     */
    public static function validateChannelForArrayConstraintsFromSetChannel(array $values = array())
    {
        $message = '';
        $invalidValues = [];
        foreach ($values as $jP_CustomerChannelsChannelItem) {
            // validation for constraint: itemType
            if (!$jP_CustomerChannelsChannelItem instanceof \StructType\JP_CustomerCodeElement) {
                $invalidValues[] = is_object($jP_CustomerChannelsChannelItem) ? get_class($jP_CustomerChannelsChannelItem) : sprintf('%s(%s)', gettype($jP_CustomerChannelsChannelItem), var_export($jP_CustomerChannelsChannelItem, true));
            }
        }
        if (!empty($invalidValues)) {
            $message = sprintf('The Channel property can only contain items of type \StructType\JP_CustomerCodeElement, %s given', is_object($invalidValues) ? get_class($invalidValues) : (is_array($invalidValues) ? implode(', ', $invalidValues) : gettype($invalidValues)));
        }
        unset($invalidValues);
        return $message;
    }
    /**
     * Set Channel value
     * @throws \InvalidArgumentException
     * @param \StructType\JP_CustomerCodeElement[] $channel
     * @return \StructType\JP_CustomerChannels
     */
    public function setChannel(array $channel = array())
    {
        // validation for constraint: array
        if ('' !== ($channelArrayErrorMessage = self::validateChannelForArrayConstraintsFromSetChannel($channel))) {
            throw new \InvalidArgumentException($channelArrayErrorMessage, __LINE__);
        }
        $this->Channel = $channel;
        return $this;
    }
    /**
     * Add item to Channel value
     * @throws \InvalidArgumentException
     * @param \StructType\JP_CustomerCodeElement $item
     * @return \StructType\JP_CustomerChannels
     */
    public function addToChannel(\StructType\JP_CustomerCodeElement $item)
    {
        // validation for constraint: itemType
        if (!$item instanceof \StructType\JP_CustomerCodeElement) {
            throw new \InvalidArgumentException(sprintf('The Channel property can only contain items of type \StructType\JP_CustomerCodeElement, %s given', is_object($item) ? get_class($item) : (is_array($item) ? implode(', ', $item) : gettype($item))), __LINE__);
        }
        $this->Channel[] = $item;
        return $this;
    }
    /**
     * Get DefaultCode value
     * @return string|null
     */
    public function getDefaultCode()
    {
        return $this->DefaultCode;
    }
    /**
     * Set DefaultCode value
     * @param string $defaultCode
     * @return \StructType\JP_CustomerChannels
     */
    public function setDefaultCode($defaultCode = null)
    {
        // validation for constraint: string
        if (!is_null($defaultCode) && !is_string($defaultCode)) {
            throw new \InvalidArgumentException(sprintf('Invalid value %s, please provide a string, %s given', var_export($defaultCode, true), gettype($defaultCode)), __LINE__);
        }
        $this->DefaultCode = $defaultCode;
        return $this;
    }
}
