<?php
/**
 * RealTimeBreakdownValue
 *
 * PHP version 7.2
 *
 * @category Class
 * @package  MuxPhp
 * @author   Mux API team
 * @link     https://docs.mux.com
 */

/**
 * Mux API
 *
 * Mux is how developers build online video. This API encompasses both Mux Video and Mux Data functionality to help you build your video-related projects better and faster than ever before.
 *
 * The version of the OpenAPI document: v1
 * Contact: devex@mux.com
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 5.0.1
 */

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

namespace MuxPhp\Models;

use \ArrayAccess;
use \MuxPhp\ObjectSerializer;

/**
 * RealTimeBreakdownValue Class Doc Comment
 *
 * @category Class
 * @package  MuxPhp
 * @author   Mux API team
 * @link     https://docs.mux.com
 * @implements \ArrayAccess<TKey, TValue>
 * @template TKey int|null
 * @template TValue mixed|null  
 */
class RealTimeBreakdownValue implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'value' => 'string',
        'negative_impact' => 'int',
        'metric_value' => 'double',
        'display_value' => 'string',
        'concurrent_viewers' => 'int',
        'starting_up_viewers' => 'int'
    ];

    /**
      * 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 = [
        'value' => null,
        'negative_impact' => 'int64',
        'metric_value' => 'double',
        'display_value' => null,
        'concurrent_viewers' => 'int64',
        'starting_up_viewers' => 'int64'
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'value' => true,
        'negative_impact' => false,
        'metric_value' => true,
        'display_value' => false,
        'concurrent_viewers' => false,
        'starting_up_viewers' => false
    ];

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

    /**
     * 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 = [
        'value' => 'value',
        'negative_impact' => 'negative_impact',
        'metric_value' => 'metric_value',
        'display_value' => 'display_value',
        'concurrent_viewers' => 'concurrent_viewers',
        'starting_up_viewers' => 'starting_up_viewers'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'value' => 'setValue',
        'negative_impact' => 'setNegativeImpact',
        'metric_value' => 'setMetricValue',
        'display_value' => 'setDisplayValue',
        'concurrent_viewers' => 'setConcurrentViewers',
        'starting_up_viewers' => 'setStartingUpViewers'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'value' => 'getValue',
        'negative_impact' => 'getNegativeImpact',
        'metric_value' => 'getMetricValue',
        'display_value' => 'getDisplayValue',
        'concurrent_viewers' => 'getConcurrentViewers',
        'starting_up_viewers' => 'getStartingUpViewers'
    ];

    /**
     * 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[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(array $data = null)
    {
        // MUX: enum hack (self::) due to OAS emitting problems.
        //      please re-integrate with mainline when possible.
        //      src: https://github.com/OpenAPITools/openapi-generator/issues/9038
        $this->setIfExists('value', $data ?? [], null);
        $this->setIfExists('negative_impact', $data ?? [], null);
        $this->setIfExists('metric_value', $data ?? [], null);
        $this->setIfExists('display_value', $data ?? [], null);
        $this->setIfExists('concurrent_viewers', $data ?? [], null);
        $this->setIfExists('starting_up_viewers', $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 value
     *
     * @return string|null
     */
    public function getValue()
    {
        return $this->container['value'];
    }

    /**
     * Sets value
     *
     * @param string|null $value value
     *
     * @return self
     */
    public function setValue($value)
    {

        if (is_null($value)) {
            array_push($this->openAPINullablesSetToNull, 'value');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('value', $nullablesSetToNull, true);
            if ($index !== false) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        $this->container['value'] = $value;

        return $this;
    }

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

    /**
     * Sets negative_impact
     *
     * @param int|null $negative_impact negative_impact
     *
     * @return self
     */
    public function setNegativeImpact($negative_impact)
    {

        if (is_null($negative_impact)) {
            throw new \InvalidArgumentException('non-nullable negative_impact cannot be null');
        }

        $this->container['negative_impact'] = $negative_impact;

        return $this;
    }

    /**
     * Gets metric_value
     *
     * @return double|null
     */
    public function getMetricValue()
    {
        return $this->container['metric_value'];
    }

    /**
     * Sets metric_value
     *
     * @param double|null $metric_value metric_value
     *
     * @return self
     */
    public function setMetricValue($metric_value)
    {

        if (is_null($metric_value)) {
            array_push($this->openAPINullablesSetToNull, 'metric_value');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('metric_value', $nullablesSetToNull, true);
            if ($index !== false) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }

        $this->container['metric_value'] = $metric_value;

        return $this;
    }

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

    /**
     * Sets display_value
     *
     * @param string|null $display_value display_value
     *
     * @return self
     */
    public function setDisplayValue($display_value)
    {

        if (is_null($display_value)) {
            throw new \InvalidArgumentException('non-nullable display_value cannot be null');
        }

        $this->container['display_value'] = $display_value;

        return $this;
    }

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

    /**
     * Sets concurrent_viewers
     *
     * @param int|null $concurrent_viewers concurrent_viewers
     *
     * @return self
     */
    public function setConcurrentViewers($concurrent_viewers)
    {

        if (is_null($concurrent_viewers)) {
            throw new \InvalidArgumentException('non-nullable concurrent_viewers cannot be null');
        }

        $this->container['concurrent_viewers'] = $concurrent_viewers;

        return $this;
    }

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

    /**
     * Sets starting_up_viewers
     *
     * @param int|null $starting_up_viewers starting_up_viewers
     *
     * @return self
     */
    public function setStartingUpViewers($starting_up_viewers)
    {

        if (is_null($starting_up_viewers)) {
            throw new \InvalidArgumentException('non-nullable starting_up_viewers cannot be null');
        }

        $this->container['starting_up_viewers'] = $starting_up_viewers;

        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(): string
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

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


