<?php
/**
 * OHLCVExchangeTimeseriesItem
 *
 * PHP version 8.1
 *
 * @category Class
 * @package  OpenAPI\Client
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * FinFeedAPI Stock REST API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: v1
 * Contact: support@apibricks.io
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.14.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 OpenAPI\Client\Model;

use \ArrayAccess;
use \OpenAPI\Client\ObjectSerializer;

/**
 * OHLCVExchangeTimeseriesItem Class Doc Comment
 *
 * @category Class
 * @description Represents a timeseries item with price and volume information.
 * @package  OpenAPI\Client
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class OHLCVExchangeTimeseriesItem implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'time_period_start' => '\DateTime',
        'time_period_end' => '\DateTime',
        'time_open' => '\DateTime',
        'time_close' => '\DateTime',
        'price_open' => 'float',
        'price_high' => 'float',
        'price_low' => 'float',
        'price_close' => 'float',
        'volume_traded' => 'float',
        'trades_count' => 'int',
        'symbol_id_exchange' => 'string'
    ];

    /**
      * 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 = [
        'time_period_start' => 'date-time',
        'time_period_end' => 'date-time',
        'time_open' => 'date-time',
        'time_close' => 'date-time',
        'price_open' => 'double',
        'price_high' => 'double',
        'price_low' => 'double',
        'price_close' => 'double',
        'volume_traded' => 'double',
        'trades_count' => 'int64',
        'symbol_id_exchange' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'time_period_start' => false,
        'time_period_end' => false,
        'time_open' => true,
        'time_close' => true,
        'price_open' => true,
        'price_high' => true,
        'price_low' => true,
        'price_close' => true,
        'volume_traded' => false,
        'trades_count' => false,
        'symbol_id_exchange' => true
    ];

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

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

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

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

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

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

    /**
     * Checks if a nullable property is set to null.
     *
     * @param string $property
     * @return bool
     */
    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
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'time_period_start' => 'time_period_start',
        'time_period_end' => 'time_period_end',
        'time_open' => 'time_open',
        'time_close' => 'time_close',
        'price_open' => 'price_open',
        'price_high' => 'price_high',
        'price_low' => 'price_low',
        'price_close' => 'price_close',
        'volume_traded' => 'volume_traded',
        'trades_count' => 'trades_count',
        'symbol_id_exchange' => 'symbol_id_exchange'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'time_period_start' => 'setTimePeriodStart',
        'time_period_end' => 'setTimePeriodEnd',
        'time_open' => 'setTimeOpen',
        'time_close' => 'setTimeClose',
        'price_open' => 'setPriceOpen',
        'price_high' => 'setPriceHigh',
        'price_low' => 'setPriceLow',
        'price_close' => 'setPriceClose',
        'volume_traded' => 'setVolumeTraded',
        'trades_count' => 'setTradesCount',
        'symbol_id_exchange' => 'setSymbolIdExchange'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'time_period_start' => 'getTimePeriodStart',
        'time_period_end' => 'getTimePeriodEnd',
        'time_open' => 'getTimeOpen',
        'time_close' => 'getTimeClose',
        'price_open' => 'getPriceOpen',
        'price_high' => 'getPriceHigh',
        'price_low' => 'getPriceLow',
        'price_close' => 'getPriceClose',
        'volume_traded' => 'getVolumeTraded',
        'trades_count' => 'getTradesCount',
        'symbol_id_exchange' => 'getSymbolIdExchange'
    ];

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


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

    /**
     * Constructor
     *
     * @param mixed[]|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('time_period_start', $data ?? [], null);
        $this->setIfExists('time_period_end', $data ?? [], null);
        $this->setIfExists('time_open', $data ?? [], null);
        $this->setIfExists('time_close', $data ?? [], null);
        $this->setIfExists('price_open', $data ?? [], null);
        $this->setIfExists('price_high', $data ?? [], null);
        $this->setIfExists('price_low', $data ?? [], null);
        $this->setIfExists('price_close', $data ?? [], null);
        $this->setIfExists('volume_traded', $data ?? [], null);
        $this->setIfExists('trades_count', $data ?? [], null);
        $this->setIfExists('symbol_id_exchange', $data ?? [], null);
    }

    /**
    * 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 string $variableName
    * @param array  $fields
    * @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;
    }

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

        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 count($this->listInvalidProperties()) === 0;
    }


    /**
     * Gets time_period_start
     *
     * @return \DateTime|null
     */
    public function getTimePeriodStart()
    {
        return $this->container['time_period_start'];
    }

    /**
     * Sets time_period_start
     *
     * @param \DateTime|null $time_period_start Gets or sets the start time of the time period.
     *
     * @return self
     */
    public function setTimePeriodStart($time_period_start)
    {
        if (is_null($time_period_start)) {
            throw new \InvalidArgumentException('non-nullable time_period_start cannot be null');
        }
        $this->container['time_period_start'] = $time_period_start;

        return $this;
    }

    /**
     * Gets time_period_end
     *
     * @return \DateTime|null
     */
    public function getTimePeriodEnd()
    {
        return $this->container['time_period_end'];
    }

    /**
     * Sets time_period_end
     *
     * @param \DateTime|null $time_period_end Gets or sets the end time of the time period.
     *
     * @return self
     */
    public function setTimePeriodEnd($time_period_end)
    {
        if (is_null($time_period_end)) {
            throw new \InvalidArgumentException('non-nullable time_period_end cannot be null');
        }
        $this->container['time_period_end'] = $time_period_end;

        return $this;
    }

    /**
     * Gets time_open
     *
     * @return \DateTime|null
     */
    public function getTimeOpen()
    {
        return $this->container['time_open'];
    }

    /**
     * Sets time_open
     *
     * @param \DateTime|null $time_open Gets or sets the time when the price opened.
     *
     * @return self
     */
    public function setTimeOpen($time_open)
    {
        if (is_null($time_open)) {
            array_push($this->openAPINullablesSetToNull, 'time_open');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('time_open', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['time_open'] = $time_open;

        return $this;
    }

    /**
     * Gets time_close
     *
     * @return \DateTime|null
     */
    public function getTimeClose()
    {
        return $this->container['time_close'];
    }

    /**
     * Sets time_close
     *
     * @param \DateTime|null $time_close Gets or sets the time when the price closed.
     *
     * @return self
     */
    public function setTimeClose($time_close)
    {
        if (is_null($time_close)) {
            array_push($this->openAPINullablesSetToNull, 'time_close');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('time_close', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['time_close'] = $time_close;

        return $this;
    }

    /**
     * Gets price_open
     *
     * @return float|null
     */
    public function getPriceOpen()
    {
        return $this->container['price_open'];
    }

    /**
     * Sets price_open
     *
     * @param float|null $price_open Gets or sets the opening price.
     *
     * @return self
     */
    public function setPriceOpen($price_open)
    {
        if (is_null($price_open)) {
            array_push($this->openAPINullablesSetToNull, 'price_open');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('price_open', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['price_open'] = $price_open;

        return $this;
    }

    /**
     * Gets price_high
     *
     * @return float|null
     */
    public function getPriceHigh()
    {
        return $this->container['price_high'];
    }

    /**
     * Sets price_high
     *
     * @param float|null $price_high Gets or sets the highest price during the time period.
     *
     * @return self
     */
    public function setPriceHigh($price_high)
    {
        if (is_null($price_high)) {
            array_push($this->openAPINullablesSetToNull, 'price_high');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('price_high', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['price_high'] = $price_high;

        return $this;
    }

    /**
     * Gets price_low
     *
     * @return float|null
     */
    public function getPriceLow()
    {
        return $this->container['price_low'];
    }

    /**
     * Sets price_low
     *
     * @param float|null $price_low Gets or sets the lowest price during the time period.
     *
     * @return self
     */
    public function setPriceLow($price_low)
    {
        if (is_null($price_low)) {
            array_push($this->openAPINullablesSetToNull, 'price_low');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('price_low', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['price_low'] = $price_low;

        return $this;
    }

    /**
     * Gets price_close
     *
     * @return float|null
     */
    public function getPriceClose()
    {
        return $this->container['price_close'];
    }

    /**
     * Sets price_close
     *
     * @param float|null $price_close Gets or sets the closing price.
     *
     * @return self
     */
    public function setPriceClose($price_close)
    {
        if (is_null($price_close)) {
            array_push($this->openAPINullablesSetToNull, 'price_close');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('price_close', $nullablesSetToNull);
            if ($index !== FALSE) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['price_close'] = $price_close;

        return $this;
    }

    /**
     * Gets volume_traded
     *
     * @return float|null
     */
    public function getVolumeTraded()
    {
        return $this->container['volume_traded'];
    }

    /**
     * Sets volume_traded
     *
     * @param float|null $volume_traded Gets or sets the total volume traded during the time period.
     *
     * @return self
     */
    public function setVolumeTraded($volume_traded)
    {
        if (is_null($volume_traded)) {
            throw new \InvalidArgumentException('non-nullable volume_traded cannot be null');
        }
        $this->container['volume_traded'] = $volume_traded;

        return $this;
    }

    /**
     * Gets trades_count
     *
     * @return int|null
     */
    public function getTradesCount()
    {
        return $this->container['trades_count'];
    }

    /**
     * Sets trades_count
     *
     * @param int|null $trades_count Gets or sets the number of trades executed during the time period.
     *
     * @return self
     */
    public function setTradesCount($trades_count)
    {
        if (is_null($trades_count)) {
            throw new \InvalidArgumentException('non-nullable trades_count cannot be null');
        }
        $this->container['trades_count'] = $trades_count;

        return $this;
    }

    /**
     * Gets symbol_id_exchange
     *
     * @return string|null
     */
    public function getSymbolIdExchange()
    {
        return $this->container['symbol_id_exchange'];
    }

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

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

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

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

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

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     * @link 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 the string presentation of the object
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

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


