<?php
/**
 * AbridgedVideoView
 *
 * 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;

/**
 * AbridgedVideoView 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 AbridgedVideoView implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'id' => 'string',
        'viewer_os_family' => 'string',
        'viewer_application_name' => 'string',
        'video_title' => 'string',
        'total_row_count' => 'int',
        'player_error_message' => 'string',
        'player_error_code' => 'string',
        'error_type_id' => 'int',
        'country_code' => 'string',
        'view_start' => 'string',
        'view_end' => 'string',
        'viewer_experience_score' => 'float',
        'watch_time' => 'int',
        'playback_failure' => 'bool'
    ];

    /**
      * 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 = [
        'id' => null,
        'viewer_os_family' => null,
        'viewer_application_name' => null,
        'video_title' => null,
        'total_row_count' => 'int64',
        'player_error_message' => null,
        'player_error_code' => null,
        'error_type_id' => 'int32',
        'country_code' => null,
        'view_start' => null,
        'view_end' => null,
        'viewer_experience_score' => 'float',
        'watch_time' => 'int32',
        'playback_failure' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'id' => false,
        'viewer_os_family' => true,
        'viewer_application_name' => true,
        'video_title' => true,
        'total_row_count' => false,
        'player_error_message' => true,
        'player_error_code' => true,
        'error_type_id' => true,
        'country_code' => true,
        'view_start' => false,
        'view_end' => false,
        'viewer_experience_score' => true,
        'watch_time' => true,
        'playback_failure' => 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 = [
        'id' => 'id',
        'viewer_os_family' => 'viewer_os_family',
        'viewer_application_name' => 'viewer_application_name',
        'video_title' => 'video_title',
        'total_row_count' => 'total_row_count',
        'player_error_message' => 'player_error_message',
        'player_error_code' => 'player_error_code',
        'error_type_id' => 'error_type_id',
        'country_code' => 'country_code',
        'view_start' => 'view_start',
        'view_end' => 'view_end',
        'viewer_experience_score' => 'viewer_experience_score',
        'watch_time' => 'watch_time',
        'playback_failure' => 'playback_failure'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'viewer_os_family' => 'setViewerOsFamily',
        'viewer_application_name' => 'setViewerApplicationName',
        'video_title' => 'setVideoTitle',
        'total_row_count' => 'setTotalRowCount',
        'player_error_message' => 'setPlayerErrorMessage',
        'player_error_code' => 'setPlayerErrorCode',
        'error_type_id' => 'setErrorTypeId',
        'country_code' => 'setCountryCode',
        'view_start' => 'setViewStart',
        'view_end' => 'setViewEnd',
        'viewer_experience_score' => 'setViewerExperienceScore',
        'watch_time' => 'setWatchTime',
        'playback_failure' => 'setPlaybackFailure'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'viewer_os_family' => 'getViewerOsFamily',
        'viewer_application_name' => 'getViewerApplicationName',
        'video_title' => 'getVideoTitle',
        'total_row_count' => 'getTotalRowCount',
        'player_error_message' => 'getPlayerErrorMessage',
        'player_error_code' => 'getPlayerErrorCode',
        'error_type_id' => 'getErrorTypeId',
        'country_code' => 'getCountryCode',
        'view_start' => 'getViewStart',
        'view_end' => 'getViewEnd',
        'viewer_experience_score' => 'getViewerExperienceScore',
        'watch_time' => 'getWatchTime',
        'playback_failure' => 'getPlaybackFailure'
    ];

    /**
     * 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('id', $data ?? [], null);
        $this->setIfExists('viewer_os_family', $data ?? [], null);
        $this->setIfExists('viewer_application_name', $data ?? [], null);
        $this->setIfExists('video_title', $data ?? [], null);
        $this->setIfExists('total_row_count', $data ?? [], null);
        $this->setIfExists('player_error_message', $data ?? [], null);
        $this->setIfExists('player_error_code', $data ?? [], null);
        $this->setIfExists('error_type_id', $data ?? [], null);
        $this->setIfExists('country_code', $data ?? [], null);
        $this->setIfExists('view_start', $data ?? [], null);
        $this->setIfExists('view_end', $data ?? [], null);
        $this->setIfExists('viewer_experience_score', $data ?? [], null);
        $this->setIfExists('watch_time', $data ?? [], null);
        $this->setIfExists('playback_failure', $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 id
     *
     * @return string|null
     */
    public function getId()
    {
        return $this->container['id'];
    }

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

    /**
     * Sets viewer_experience_score
     *
     * @param float|null $viewer_experience_score viewer_experience_score
     *
     * @return self
     */
    public function setViewerExperienceScore($viewer_experience_score)
    {

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

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

        return $this;
    }

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

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

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

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

        return $this;
    }

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

    /**
     * Sets playback_failure
     *
     * @param bool|null $playback_failure playback_failure
     *
     * @return self
     */
    public function setPlaybackFailure($playback_failure)
    {

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

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

        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));
    }
}


