<?php

// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.

namespace Algolia\AlgoliaSearch\Model\Composition;

use Algolia\AlgoliaSearch\Model\AbstractModel;
use Algolia\AlgoliaSearch\Model\ModelInterface;

/**
 * InjectionInjectedItem Class Doc Comment.
 *
 * @category Class
 */
class InjectionInjectedItem extends AbstractModel implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $modelTypes = [
        'key' => 'string',
        'source' => '\Algolia\AlgoliaSearch\Model\Composition\InjectedItemSource',
        'position' => 'int',
        'length' => 'int',
        'metadata' => '\Algolia\AlgoliaSearch\Model\Composition\InjectedItemMetadata',
    ];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static $modelFormats = [
        'key' => null,
        'source' => null,
        'position' => null,
        'length' => null,
        'metadata' => null,
    ];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'key' => 'key',
        'source' => 'source',
        'position' => 'position',
        'length' => 'length',
        'metadata' => 'metadata',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static $setters = [
        'key' => 'setKey',
        'source' => 'setSource',
        'position' => 'setPosition',
        'length' => 'setLength',
        'metadata' => 'setMetadata',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static $getters = [
        'key' => 'getKey',
        'source' => 'getSource',
        'position' => 'getPosition',
        'length' => 'getLength',
        'metadata' => 'getMetadata',
    ];

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

    /**
     * Constructor.
     *
     * @param mixed[] $data Associated array of property values
     */
    public function __construct(?array $data = null)
    {
        if (isset($data['key'])) {
            $this->container['key'] = $data['key'];
        }
        if (isset($data['source'])) {
            $this->container['source'] = $data['source'];
        }
        if (isset($data['position'])) {
            $this->container['position'] = $data['position'];
        }
        if (isset($data['length'])) {
            $this->container['length'] = $data['length'];
        }
        if (isset($data['metadata'])) {
            $this->container['metadata'] = $data['metadata'];
        }
    }

    /**
     * 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 property to type mappings. Used for (de)serialization.
     *
     * @return array
     */
    public static function modelTypes()
    {
        return self::$modelTypes;
    }

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

    /**
     * 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;
    }

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

        if (!isset($this->container['key']) || null === $this->container['key']) {
            $invalidProperties[] = "'key' can't be null";
        }
        if (!isset($this->container['source']) || null === $this->container['source']) {
            $invalidProperties[] = "'source' can't be null";
        }
        if (!isset($this->container['position']) || null === $this->container['position']) {
            $invalidProperties[] = "'position' can't be null";
        }
        if (!isset($this->container['length']) || null === $this->container['length']) {
            $invalidProperties[] = "'length' 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 key.
     *
     * @return string
     */
    public function getKey()
    {
        return $this->container['key'] ?? null;
    }

    /**
     * Sets key.
     *
     * @param string $key injected Item unique identifier
     *
     * @return self
     */
    public function setKey($key)
    {
        $this->container['key'] = $key;

        return $this;
    }

    /**
     * Gets source.
     *
     * @return InjectedItemSource
     */
    public function getSource()
    {
        return $this->container['source'] ?? null;
    }

    /**
     * Sets source.
     *
     * @param InjectedItemSource $source source
     *
     * @return self
     */
    public function setSource($source)
    {
        $this->container['source'] = $source;

        return $this;
    }

    /**
     * Gets position.
     *
     * @return int
     */
    public function getPosition()
    {
        return $this->container['position'] ?? null;
    }

    /**
     * Sets position.
     *
     * @param int $position position
     *
     * @return self
     */
    public function setPosition($position)
    {
        $this->container['position'] = $position;

        return $this;
    }

    /**
     * Gets length.
     *
     * @return int
     */
    public function getLength()
    {
        return $this->container['length'] ?? null;
    }

    /**
     * Sets length.
     *
     * @param int $length length
     *
     * @return self
     */
    public function setLength($length)
    {
        $this->container['length'] = $length;

        return $this;
    }

    /**
     * Gets metadata.
     *
     * @return null|InjectedItemMetadata
     */
    public function getMetadata()
    {
        return $this->container['metadata'] ?? null;
    }

    /**
     * Sets metadata.
     *
     * @param null|InjectedItemMetadata $metadata metadata
     *
     * @return self
     */
    public function setMetadata($metadata)
    {
        $this->container['metadata'] = $metadata;

        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
     */
    public function offsetGet($offset): mixed
    {
        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]);
    }
}
