<?php
/**
 * SegmentsProfileMetricCondition
 *
 * PHP version 7.4
 *
 * @category Class
 * @package  KlaviyoAPI
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Klaviyo API
 *
 * The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.
 *
 * Contact: developers@klaviyo.com
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.1.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 KlaviyoAPI\Model;

use \ArrayAccess;
use \KlaviyoAPI\ObjectSerializer;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'type' => '\KlaviyoAPI\Model\ProfileMetricEnum',
        'metric_id' => 'string',
        'measurement' => 'string',
        'measurement_filter' => '\KlaviyoAPI\Model\NumericOperatorFilter',
        'timeframe_filter' => '\KlaviyoAPI\Model\SegmentsProfileMetricConditionTimeframeFilter',
        'metric_filters' => '\KlaviyoAPI\Model\ProfileMetricPropertyFilter[]'
    ];

    /**
      * 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 = [
        'type' => null,
        'metric_id' => null,
        'measurement' => null,
        'measurement_filter' => null,
        'timeframe_filter' => null,
        'metric_filters' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'type' => false,
		'metric_id' => false,
		'measurement' => false,
		'measurement_filter' => false,
		'timeframe_filter' => false,
		'metric_filters' => 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;
    }

    /**
     * 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 = [
        'type' => 'type',
        'metric_id' => 'metric_id',
        'measurement' => 'measurement',
        'measurement_filter' => 'measurement_filter',
        'timeframe_filter' => 'timeframe_filter',
        'metric_filters' => 'metric_filters'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'type' => 'setType',
        'metric_id' => 'setMetricId',
        'measurement' => 'setMeasurement',
        'measurement_filter' => 'setMeasurementFilter',
        'timeframe_filter' => 'setTimeframeFilter',
        'metric_filters' => 'setMetricFilters'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'type' => 'getType',
        'metric_id' => 'getMetricId',
        'measurement' => 'getMeasurement',
        'measurement_filter' => 'getMeasurementFilter',
        'timeframe_filter' => 'getTimeframeFilter',
        'metric_filters' => 'getMetricFilters'
    ];

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

    public const MEASUREMENT_COUNT = 'count';
    public const MEASUREMENT_SUM = 'sum';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getMeasurementAllowableValues()
    {
        return [
            self::MEASUREMENT_COUNT,
            self::MEASUREMENT_SUM,
        ];
    }

    /**
     * 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('type', $data ?? [], null);
        $this->setIfExists('metric_id', $data ?? [], null);
        $this->setIfExists('measurement', $data ?? [], null);
        $this->setIfExists('measurement_filter', $data ?? [], null);
        $this->setIfExists('timeframe_filter', $data ?? [], null);
        $this->setIfExists('metric_filters', $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 = [];

        if ($this->container['type'] === null) {
            $invalidProperties[] = "'type' can't be null";
        }
        if ($this->container['metric_id'] === null) {
            $invalidProperties[] = "'metric_id' can't be null";
        }
        if ($this->container['measurement'] === null) {
            $invalidProperties[] = "'measurement' can't be null";
        }
        $allowedValues = $this->getMeasurementAllowableValues();
        if (!is_null($this->container['measurement']) && !in_array($this->container['measurement'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'measurement', must be one of '%s'",
                $this->container['measurement'],
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['measurement_filter'] === null) {
            $invalidProperties[] = "'measurement_filter' can't be null";
        }
        if ($this->container['timeframe_filter'] === null) {
            $invalidProperties[] = "'timeframe_filter' 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 count($this->listInvalidProperties()) === 0;
    }


    /**
     * Gets type
     *
     * @return \KlaviyoAPI\Model\ProfileMetricEnum
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     *
     * @param \KlaviyoAPI\Model\ProfileMetricEnum $type type
     *
     * @return self
     */
    public function setType($type)
    {

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

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

        return $this;
    }

    /**
     * Gets metric_id
     *
     * @return string
     */
    public function getMetricId()
    {
        return $this->container['metric_id'];
    }

    /**
     * Sets metric_id
     *
     * @param string $metric_id metric_id
     *
     * @return self
     */
    public function setMetricId($metric_id)
    {

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

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

        return $this;
    }

    /**
     * Gets measurement
     *
     * @return string
     */
    public function getMeasurement()
    {
        return $this->container['measurement'];
    }

    /**
     * Sets measurement
     *
     * @param string $measurement Measurements for profile metrics.
     *
     * @return self
     */
    public function setMeasurement($measurement)
    {
        $allowedValues = $this->getMeasurementAllowableValues();
        if (!in_array($measurement, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'measurement', must be one of '%s'",
                    $measurement,
                    implode("', '", $allowedValues)
                )
            );
        }

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

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

        return $this;
    }

    /**
     * Gets measurement_filter
     *
     * @return \KlaviyoAPI\Model\NumericOperatorFilter
     */
    public function getMeasurementFilter()
    {
        return $this->container['measurement_filter'];
    }

    /**
     * Sets measurement_filter
     *
     * @param \KlaviyoAPI\Model\NumericOperatorFilter $measurement_filter measurement_filter
     *
     * @return self
     */
    public function setMeasurementFilter($measurement_filter)
    {

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

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

        return $this;
    }

    /**
     * Gets timeframe_filter
     *
     * @return \KlaviyoAPI\Model\SegmentsProfileMetricConditionTimeframeFilter
     */
    public function getTimeframeFilter()
    {
        return $this->container['timeframe_filter'];
    }

    /**
     * Sets timeframe_filter
     *
     * @param \KlaviyoAPI\Model\SegmentsProfileMetricConditionTimeframeFilter $timeframe_filter timeframe_filter
     *
     * @return self
     */
    public function setTimeframeFilter($timeframe_filter)
    {

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

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

        return $this;
    }

    /**
     * Gets metric_filters
     *
     * @return \KlaviyoAPI\Model\ProfileMetricPropertyFilter[]|null
     */
    public function getMetricFilters()
    {
        return $this->container['metric_filters'];
    }

    /**
     * Sets metric_filters
     *
     * @param \KlaviyoAPI\Model\ProfileMetricPropertyFilter[]|null $metric_filters metric_filters
     *
     * @return self
     */
    public function setMetricFilters($metric_filters)
    {

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

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

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


