<?php

/**
 * FlowSyndication.
 *
 * PHP version 7.4
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Sync Core.
 *
 * The Sync Core that sends and receives content from all connected sites and services for Content Sync.
 *
 * The version of the OpenAPI document: 1.0
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.4.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace EdgeBox\SyncCore\V2\Raw\Model;

use EdgeBox\SyncCore\V2\Raw\ObjectSerializer;

/**
 * FlowSyndication Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class FlowSyndication implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     *
     * @var string
     */
    protected static $openAPIModelName = 'FlowSyndication';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'mode' => 'FlowSyndicationMode',
        'clone' => 'bool',
        'filters' => '\EdgeBox\SyncCore\V2\Raw\Model\FlowSyndicationFilter[]',
        'syndicateDeletions' => 'bool',
        'pool' => '\EdgeBox\SyncCore\V2\Raw\Model\RuntimeRemoteEntityDependencyWithDependenciesEntity',
        'entityTypes' => '\EdgeBox\SyncCore\V2\Raw\Model\DynamicReference[]',
        'entityTypeVersions' => '\EdgeBox\SyncCore\V2\Raw\Model\DynamicReference[]',
    ];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static $openAPIFormats = [
        'mode' => null,
        'clone' => null,
        'filters' => null,
        'syndicateDeletions' => null,
        'pool' => null,
        'entityTypes' => null,
        'entityTypeVersions' => null,
    ];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'mode' => false,
        'clone' => true,
        'filters' => true,
        'syndicateDeletions' => true,
        'pool' => false,
        'entityTypes' => false,
        'entityTypeVersions' => false,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'mode' => 'mode',
        'clone' => 'clone',
        'filters' => 'filters',
        'syndicateDeletions' => 'syndicateDeletions',
        'pool' => 'pool',
        'entityTypes' => 'entityTypes',
        'entityTypeVersions' => 'entityTypeVersions',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'mode' => 'setMode',
        'clone' => 'setClone',
        'filters' => 'setFilters',
        'syndicateDeletions' => 'setSyndicateDeletions',
        'pool' => 'setPool',
        'entityTypes' => 'setEntityTypes',
        'entityTypeVersions' => 'setEntityTypeVersions',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'mode' => 'getMode',
        'clone' => 'getClone',
        'filters' => 'getFilters',
        'syndicateDeletions' => 'getSyndicateDeletions',
        'pool' => 'getPool',
        'entityTypes' => 'getEntityTypes',
        'entityTypeVersions' => 'getEntityTypeVersions',
    ];

    /**
     * Associative array for storing property values.
     *
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor.
     *
     * @param mixed[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('mode', $data ?? [], null);
        $this->setIfExists('clone', $data ?? [], null);
        $this->setIfExists('filters', $data ?? [], null);
        $this->setIfExists('syndicateDeletions', $data ?? [], null);
        $this->setIfExists('pool', $data ?? [], null);
        $this->setIfExists('entityTypes', $data ?? [], null);
        $this->setIfExists('entityTypeVersions', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @return array
     */
    public static function openAPITypes()
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @return array
     */
    public static function openAPIFormats()
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @return array
     */
    public static function attributeMap()
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @return array
     */
    public static function setters()
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @return array
     */
    public static function getters()
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     *
     * @return string
     */
    public function getModelName()
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        if (null === $this->container['mode']) {
            $invalidProperties[] = "'mode' can't be null";
        }
        if (null === $this->container['pool']) {
            $invalidProperties[] = "'pool' can't be null";
        }
        if (null === $this->container['entityTypes']) {
            $invalidProperties[] = "'entityTypes' can't be null";
        }
        if (null === $this->container['entityTypeVersions']) {
            $invalidProperties[] = "'entityTypeVersions' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid()
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets mode.
     *
     * @return FlowSyndicationMode
     */
    public function getMode()
    {
        return $this->container['mode'];
    }

    /**
     * Sets mode.
     *
     * @param FlowSyndicationMode $mode mode
     *
     * @return self
     */
    public function setMode($mode)
    {
        if (is_null($mode)) {
            throw new \InvalidArgumentException('non-nullable mode cannot be null');
        }
        $this->container['mode'] = $mode;

        return $this;
    }

    /**
     * Gets clone.
     *
     * @return null|bool
     */
    public function getClone()
    {
        return $this->container['clone'];
    }

    /**
     * Sets clone.
     *
     * @param null|bool $clone clone
     *
     * @return self
     */
    public function setClone($clone)
    {
        if (is_null($clone)) {
            array_push($this->openAPINullablesSetToNull, 'clone');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('clone', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['clone'] = $clone;

        return $this;
    }

    /**
     * Gets filters.
     *
     * @return null|FlowSyndicationFilter[]
     */
    public function getFilters()
    {
        return $this->container['filters'];
    }

    /**
     * Sets filters.
     *
     * @param null|FlowSyndicationFilter[] $filters filters
     *
     * @return self
     */
    public function setFilters($filters)
    {
        if (is_null($filters)) {
            array_push($this->openAPINullablesSetToNull, 'filters');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('filters', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['filters'] = $filters;

        return $this;
    }

    /**
     * Gets syndicateDeletions.
     *
     * @return null|bool
     */
    public function getSyndicateDeletions()
    {
        return $this->container['syndicateDeletions'];
    }

    /**
     * Sets syndicateDeletions.
     *
     * @param null|bool $syndicateDeletions syndicateDeletions
     *
     * @return self
     */
    public function setSyndicateDeletions($syndicateDeletions)
    {
        if (is_null($syndicateDeletions)) {
            array_push($this->openAPINullablesSetToNull, 'syndicateDeletions');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('syndicateDeletions', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['syndicateDeletions'] = $syndicateDeletions;

        return $this;
    }

    /**
     * Gets pool.
     *
     * @return RuntimeRemoteEntityDependencyWithDependenciesEntity
     */
    public function getPool()
    {
        return $this->container['pool'];
    }

    /**
     * Sets pool.
     *
     * @param RuntimeRemoteEntityDependencyWithDependenciesEntity $pool pool
     *
     * @return self
     */
    public function setPool($pool)
    {
        if (is_null($pool)) {
            throw new \InvalidArgumentException('non-nullable pool cannot be null');
        }
        $this->container['pool'] = $pool;

        return $this;
    }

    /**
     * Gets entityTypes.
     *
     * @return DynamicReference[]
     */
    public function getEntityTypes()
    {
        return $this->container['entityTypes'];
    }

    /**
     * Sets entityTypes.
     *
     * @param DynamicReference[] $entityTypes entityTypes
     *
     * @return self
     */
    public function setEntityTypes($entityTypes)
    {
        if (is_null($entityTypes)) {
            throw new \InvalidArgumentException('non-nullable entityTypes cannot be null');
        }
        $this->container['entityTypes'] = $entityTypes;

        return $this;
    }

    /**
     * Gets entityTypeVersions.
     *
     * @return DynamicReference[]
     */
    public function getEntityTypeVersions()
    {
        return $this->container['entityTypeVersions'];
    }

    /**
     * Sets entityTypeVersions.
     *
     * @param DynamicReference[] $entityTypeVersions entityTypeVersions
     *
     * @return self
     */
    public function setEntityTypeVersions($entityTypeVersions)
    {
        if (is_null($entityTypeVersions)) {
            throw new \InvalidArgumentException('non-nullable entityTypeVersions cannot be null');
        }
        $this->container['entityTypeVersions'] = $entityTypeVersions;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset)
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     * of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     *
     * @return string
     */
    public function toHeaderValue()
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed  $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
