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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'type' => '\KlaviyoAPI\Model\LowInventoryEnum',
        'product_level' => 'string',
        'trigger_filter' => '\KlaviyoAPI\Model\LowInventoryConditionFilter',
        'inventory_count' => 'int',
        'audience' => 'string[]',
        'timeframe_days' => '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 = [
        'type' => null,
        'product_level' => null,
        'trigger_filter' => null,
        'inventory_count' => null,
        'audience' => null,
        'timeframe_days' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'type' => false,
		'product_level' => false,
		'trigger_filter' => false,
		'inventory_count' => false,
		'audience' => false,
		'timeframe_days' => 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 = [
        'type' => 'type',
        'product_level' => 'product_level',
        'trigger_filter' => 'trigger_filter',
        'inventory_count' => 'inventory_count',
        'audience' => 'audience',
        'timeframe_days' => 'timeframe_days'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'type' => 'setType',
        'product_level' => 'setProductLevel',
        'trigger_filter' => 'setTriggerFilter',
        'inventory_count' => 'setInventoryCount',
        'audience' => 'setAudience',
        'timeframe_days' => 'setTimeframeDays'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'type' => 'getType',
        'product_level' => 'getProductLevel',
        'trigger_filter' => 'getTriggerFilter',
        'inventory_count' => 'getInventoryCount',
        'audience' => 'getAudience',
        'timeframe_days' => 'getTimeframeDays'
    ];

    /**
     * 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 PRODUCT_LEVEL_PRODUCT = 'product';
    public const PRODUCT_LEVEL_VARIANT = 'variant';
    public const AUDIENCE_ADDED_TO_CART = 'added-to-cart';
    public const AUDIENCE_CHECKOUT_STARTED = 'checkout-started';
    public const AUDIENCE_VIEWED = 'viewed';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getProductLevelAllowableValues()
    {
        return [
            self::PRODUCT_LEVEL_PRODUCT,
            self::PRODUCT_LEVEL_VARIANT,
        ];
    }

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getAudienceAllowableValues()
    {
        return [
            self::AUDIENCE_ADDED_TO_CART,
            self::AUDIENCE_CHECKOUT_STARTED,
            self::AUDIENCE_VIEWED,
        ];
    }

    /**
     * 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('product_level', $data ?? [], null);
        $this->setIfExists('trigger_filter', $data ?? [], null);
        $this->setIfExists('inventory_count', $data ?? [], null);
        $this->setIfExists('audience', $data ?? [], null);
        $this->setIfExists('timeframe_days', $data ?? [], 30);
    }

    /**
    * 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['product_level'] === null) {
            $invalidProperties[] = "'product_level' can't be null";
        }
        $allowedValues = $this->getProductLevelAllowableValues();
        if (!is_null($this->container['product_level']) && !in_array($this->container['product_level'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'product_level', must be one of '%s'",
                $this->container['product_level'],
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['trigger_filter'] === null) {
            $invalidProperties[] = "'trigger_filter' can't be null";
        }
        if ($this->container['inventory_count'] === null) {
            $invalidProperties[] = "'inventory_count' can't be null";
        }
        if ($this->container['audience'] === null) {
            $invalidProperties[] = "'audience' 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\LowInventoryEnum
     */
    public function getType()
    {
        return $this->container['type'];
    }

    /**
     * Sets type
     *
     * @param \KlaviyoAPI\Model\LowInventoryEnum $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 product_level
     *
     * @return string
     */
    public function getProductLevel()
    {
        return $this->container['product_level'];
    }

    /**
     * Sets product_level
     *
     * @param string $product_level Low inventory product level.
     *
     * @return self
     */
    public function setProductLevel($product_level)
    {
        $allowedValues = $this->getProductLevelAllowableValues();
        if (!in_array($product_level, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'product_level', must be one of '%s'",
                    $product_level,
                    implode("', '", $allowedValues)
                )
            );
        }

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

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

        return $this;
    }

    /**
     * Gets trigger_filter
     *
     * @return \KlaviyoAPI\Model\LowInventoryConditionFilter
     */
    public function getTriggerFilter()
    {
        return $this->container['trigger_filter'];
    }

    /**
     * Sets trigger_filter
     *
     * @param \KlaviyoAPI\Model\LowInventoryConditionFilter $trigger_filter trigger_filter
     *
     * @return self
     */
    public function setTriggerFilter($trigger_filter)
    {

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

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

        return $this;
    }

    /**
     * Gets inventory_count
     *
     * @return int
     */
    public function getInventoryCount()
    {
        return $this->container['inventory_count'];
    }

    /**
     * Sets inventory_count
     *
     * @param int $inventory_count inventory_count
     *
     * @return self
     */
    public function setInventoryCount($inventory_count)
    {

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

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

        return $this;
    }

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

    /**
     * Sets audience
     *
     * @param string[] $audience audience
     *
     * @return self
     */
    public function setAudience($audience)
    {
        $allowedValues = $this->getAudienceAllowableValues();
        if (array_diff($audience, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'audience', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }

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

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

        return $this;
    }

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

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

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

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

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


