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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'statistics' => 'string[]',
        'timeframe' => '\KlaviyoAPI\Model\CampaignValuesRequestDTOResourceObjectAttributesTimeframe',
        'conversion_metric_id' => 'string',
        'filter' => '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 = [
        'statistics' => null,
        'timeframe' => null,
        'conversion_metric_id' => null,
        'filter' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'statistics' => false,
		'timeframe' => false,
		'conversion_metric_id' => false,
		'filter' => 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 = [
        'statistics' => 'statistics',
        'timeframe' => 'timeframe',
        'conversion_metric_id' => 'conversion_metric_id',
        'filter' => 'filter'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'statistics' => 'setStatistics',
        'timeframe' => 'setTimeframe',
        'conversion_metric_id' => 'setConversionMetricId',
        'filter' => 'setFilter'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'statistics' => 'getStatistics',
        'timeframe' => 'getTimeframe',
        'conversion_metric_id' => 'getConversionMetricId',
        'filter' => 'getFilter'
    ];

    /**
     * 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 STATISTICS_AVERAGE_ORDER_VALUE = 'average_order_value';
    public const STATISTICS_BOUNCE_RATE = 'bounce_rate';
    public const STATISTICS_BOUNCED = 'bounced';
    public const STATISTICS_BOUNCED_OR_FAILED = 'bounced_or_failed';
    public const STATISTICS_BOUNCED_OR_FAILED_RATE = 'bounced_or_failed_rate';
    public const STATISTICS_CLICK_RATE = 'click_rate';
    public const STATISTICS_CLICK_TO_OPEN_RATE = 'click_to_open_rate';
    public const STATISTICS_CLICKS = 'clicks';
    public const STATISTICS_CLICKS_UNIQUE = 'clicks_unique';
    public const STATISTICS_CONVERSION_RATE = 'conversion_rate';
    public const STATISTICS_CONVERSION_UNIQUES = 'conversion_uniques';
    public const STATISTICS_CONVERSION_VALUE = 'conversion_value';
    public const STATISTICS_CONVERSIONS = 'conversions';
    public const STATISTICS_DELIVERED = 'delivered';
    public const STATISTICS_DELIVERY_RATE = 'delivery_rate';
    public const STATISTICS_FAILED = 'failed';
    public const STATISTICS_FAILED_RATE = 'failed_rate';
    public const STATISTICS_OPEN_RATE = 'open_rate';
    public const STATISTICS_OPENS = 'opens';
    public const STATISTICS_OPENS_UNIQUE = 'opens_unique';
    public const STATISTICS_RECIPIENTS = 'recipients';
    public const STATISTICS_REVENUE_PER_RECIPIENT = 'revenue_per_recipient';
    public const STATISTICS_SPAM_COMPLAINT_RATE = 'spam_complaint_rate';
    public const STATISTICS_SPAM_COMPLAINTS = 'spam_complaints';
    public const STATISTICS_UNSUBSCRIBE_RATE = 'unsubscribe_rate';
    public const STATISTICS_UNSUBSCRIBE_UNIQUES = 'unsubscribe_uniques';
    public const STATISTICS_UNSUBSCRIBES = 'unsubscribes';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getStatisticsAllowableValues()
    {
        return [
            self::STATISTICS_AVERAGE_ORDER_VALUE,
            self::STATISTICS_BOUNCE_RATE,
            self::STATISTICS_BOUNCED,
            self::STATISTICS_BOUNCED_OR_FAILED,
            self::STATISTICS_BOUNCED_OR_FAILED_RATE,
            self::STATISTICS_CLICK_RATE,
            self::STATISTICS_CLICK_TO_OPEN_RATE,
            self::STATISTICS_CLICKS,
            self::STATISTICS_CLICKS_UNIQUE,
            self::STATISTICS_CONVERSION_RATE,
            self::STATISTICS_CONVERSION_UNIQUES,
            self::STATISTICS_CONVERSION_VALUE,
            self::STATISTICS_CONVERSIONS,
            self::STATISTICS_DELIVERED,
            self::STATISTICS_DELIVERY_RATE,
            self::STATISTICS_FAILED,
            self::STATISTICS_FAILED_RATE,
            self::STATISTICS_OPEN_RATE,
            self::STATISTICS_OPENS,
            self::STATISTICS_OPENS_UNIQUE,
            self::STATISTICS_RECIPIENTS,
            self::STATISTICS_REVENUE_PER_RECIPIENT,
            self::STATISTICS_SPAM_COMPLAINT_RATE,
            self::STATISTICS_SPAM_COMPLAINTS,
            self::STATISTICS_UNSUBSCRIBE_RATE,
            self::STATISTICS_UNSUBSCRIBE_UNIQUES,
            self::STATISTICS_UNSUBSCRIBES,
        ];
    }

    /**
     * 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('statistics', $data ?? [], null);
        $this->setIfExists('timeframe', $data ?? [], null);
        $this->setIfExists('conversion_metric_id', $data ?? [], null);
        $this->setIfExists('filter', $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['statistics'] === null) {
            $invalidProperties[] = "'statistics' can't be null";
        }
        if ($this->container['timeframe'] === null) {
            $invalidProperties[] = "'timeframe' can't be null";
        }
        if ($this->container['conversion_metric_id'] === null) {
            $invalidProperties[] = "'conversion_metric_id' 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 statistics
     *
     * @return string[]
     */
    public function getStatistics()
    {
        return $this->container['statistics'];
    }

    /**
     * Sets statistics
     *
     * @param string[] $statistics List of statistics to query for. All rate statistics will be returned in fractional form [0.0, 1.0]
     *
     * @return self
     */
    public function setStatistics($statistics)
    {
        $allowedValues = $this->getStatisticsAllowableValues();
        if (array_diff($statistics, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'statistics', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }

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

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

        return $this;
    }

    /**
     * Gets timeframe
     *
     * @return \KlaviyoAPI\Model\CampaignValuesRequestDTOResourceObjectAttributesTimeframe
     */
    public function getTimeframe()
    {
        return $this->container['timeframe'];
    }

    /**
     * Sets timeframe
     *
     * @param \KlaviyoAPI\Model\CampaignValuesRequestDTOResourceObjectAttributesTimeframe $timeframe timeframe
     *
     * @return self
     */
    public function setTimeframe($timeframe)
    {

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

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

        return $this;
    }

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

    /**
     * Sets conversion_metric_id
     *
     * @param string $conversion_metric_id ID of the metric to be used for conversion statistics
     *
     * @return self
     */
    public function setConversionMetricId($conversion_metric_id)
    {

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

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

        return $this;
    }

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

    /**
     * Sets filter
     *
     * @param string|null $filter API filter string used to filter the query. Allowed filters are send_channel, campaign_id, campaign_message_id. Allowed operators are equals, contains-any. Only one filter can be used per attribute, only AND can be used as a combination operator. Max of 100 messages per ANY filter. When filtering on send_channel, allowed values are email, sms, push-notification.
     *
     * @return self
     */
    public function setFilter($filter)
    {

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

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

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


