<?php
/**
 * Promotion
 *
 * PHP version 8.1
 *
 * @category Class
 * @package  Vend
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * API 2026-07
 *
 * Lightspeed Retail (X-Series) API.
 *
 * The version of the OpenAPI document: 2026-07
 * Contact: x-series.api@lightspeedhq.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.23.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 Vend\Model;

use \ArrayAccess;
use \Vend\ObjectSerializer;

/**
 * Promotion Class Doc Comment
 *
 * @category Class
 * @description A Promotion defines rules and actions for discounting products as part of a sales promotion.
 * @package  Vend
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class Promotion implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'action' => '\Vend\Model\Action',
        'add_promo_code' => '\Vend\Model\PromoCode[]',
        'channels' => 'string[]',
        'condition' => '\Vend\Model\Condition',
        'customer_group_ids' => 'string[]',
        'description' => 'string',
        'end_time' => 'string',
        'id' => 'string',
        'loyalty_multiplier' => 'float',
        'name' => 'string',
        'outlet_ids' => 'string[]',
        'promo_code_summary' => '\Vend\Model\PromotionPromoCodeSummary',
        'start_time' => 'string',
        'status' => 'string',
        'use_promo_code' => '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 = [
        'action' => null,
        'add_promo_code' => null,
        'channels' => null,
        'condition' => null,
        'customer_group_ids' => null,
        'description' => null,
        'end_time' => null,
        'id' => null,
        'loyalty_multiplier' => 'double',
        'name' => null,
        'outlet_ids' => null,
        'promo_code_summary' => null,
        'start_time' => null,
        'status' => null,
        'use_promo_code' => null
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'action' => false,
        'add_promo_code' => false,
        'channels' => false,
        'condition' => false,
        'customer_group_ids' => false,
        'description' => false,
        'end_time' => false,
        'id' => false,
        'loyalty_multiplier' => false,
        'name' => false,
        'outlet_ids' => false,
        'promo_code_summary' => false,
        'start_time' => false,
        'status' => false,
        'use_promo_code' => 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;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null
     *
     * @param boolean[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $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 = [
        'action' => 'action',
        'add_promo_code' => 'add_promo_code',
        'channels' => 'channels',
        'condition' => 'condition',
        'customer_group_ids' => 'customer_group_ids',
        'description' => 'description',
        'end_time' => 'end_time',
        'id' => 'id',
        'loyalty_multiplier' => 'loyalty_multiplier',
        'name' => 'name',
        'outlet_ids' => 'outlet_ids',
        'promo_code_summary' => 'promo_code_summary',
        'start_time' => 'start_time',
        'status' => 'status',
        'use_promo_code' => 'use_promo_code'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'action' => 'setAction',
        'add_promo_code' => 'setAddPromoCode',
        'channels' => 'setChannels',
        'condition' => 'setCondition',
        'customer_group_ids' => 'setCustomerGroupIds',
        'description' => 'setDescription',
        'end_time' => 'setEndTime',
        'id' => 'setId',
        'loyalty_multiplier' => 'setLoyaltyMultiplier',
        'name' => 'setName',
        'outlet_ids' => 'setOutletIds',
        'promo_code_summary' => 'setPromoCodeSummary',
        'start_time' => 'setStartTime',
        'status' => 'setStatus',
        'use_promo_code' => 'setUsePromoCode'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'action' => 'getAction',
        'add_promo_code' => 'getAddPromoCode',
        'channels' => 'getChannels',
        'condition' => 'getCondition',
        'customer_group_ids' => 'getCustomerGroupIds',
        'description' => 'getDescription',
        'end_time' => 'getEndTime',
        'id' => 'getId',
        'loyalty_multiplier' => 'getLoyaltyMultiplier',
        'name' => 'getName',
        'outlet_ids' => 'getOutletIds',
        'promo_code_summary' => 'getPromoCodeSummary',
        'start_time' => 'getStartTime',
        'status' => 'getStatus',
        'use_promo_code' => 'getUsePromoCode'
    ];

    /**
     * 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[]|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('action', $data ?? [], null);
        $this->setIfExists('add_promo_code', $data ?? [], null);
        $this->setIfExists('channels', $data ?? [], null);
        $this->setIfExists('condition', $data ?? [], null);
        $this->setIfExists('customer_group_ids', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('end_time', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('loyalty_multiplier', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('outlet_ids', $data ?? [], null);
        $this->setIfExists('promo_code_summary', $data ?? [], null);
        $this->setIfExists('start_time', $data ?? [], null);
        $this->setIfExists('status', $data ?? [], null);
        $this->setIfExists('use_promo_code', $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['action'] === null) {
            $invalidProperties[] = "'action' can't be null";
        }
        if ($this->container['condition'] === null) {
            $invalidProperties[] = "'condition' can't be null";
        }
        if ($this->container['name'] === null) {
            $invalidProperties[] = "'name' can't be null";
        }
        if ($this->container['start_time'] === null) {
            $invalidProperties[] = "'start_time' can't be null";
        }
        if ($this->container['use_promo_code'] === null) {
            $invalidProperties[] = "'use_promo_code' 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 action
     *
     * @return \Vend\Model\Action
     */
    public function getAction()
    {
        return $this->container['action'];
    }

    /**
     * Sets action
     *
     * @param \Vend\Model\Action $action action
     *
     * @return self
     */
    public function setAction($action)
    {
        if (is_null($action)) {
            throw new \InvalidArgumentException('non-nullable action cannot be null');
        }
        $this->container['action'] = $action;

        return $this;
    }

    /**
     * Gets add_promo_code
     *
     * @return \Vend\Model\PromoCode[]|null
     */
    public function getAddPromoCode()
    {
        return $this->container['add_promo_code'];
    }

    /**
     * Sets add_promo_code
     *
     * @param \Vend\Model\PromoCode[]|null $add_promo_code A list of promo codes to associate with this promotion.
     *
     * @return self
     */
    public function setAddPromoCode($add_promo_code)
    {
        if (is_null($add_promo_code)) {
            throw new \InvalidArgumentException('non-nullable add_promo_code cannot be null');
        }
        $this->container['add_promo_code'] = $add_promo_code;

        return $this;
    }

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

    /**
     * Sets channels
     *
     * @param string[]|null $channels A list of channels for the promotion. Can be `Register`, `Ecommerce`.
     *
     * @return self
     */
    public function setChannels($channels)
    {
        if (is_null($channels)) {
            throw new \InvalidArgumentException('non-nullable channels cannot be null');
        }
        $this->container['channels'] = $channels;

        return $this;
    }

    /**
     * Gets condition
     *
     * @return \Vend\Model\Condition
     */
    public function getCondition()
    {
        return $this->container['condition'];
    }

    /**
     * Sets condition
     *
     * @param \Vend\Model\Condition $condition condition
     *
     * @return self
     */
    public function setCondition($condition)
    {
        if (is_null($condition)) {
            throw new \InvalidArgumentException('non-nullable condition cannot be null');
        }
        $this->container['condition'] = $condition;

        return $this;
    }

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

    /**
     * Sets customer_group_ids
     *
     * @param string[]|null $customer_group_ids A list of customer group IDs for the promotion.
     *
     * @return self
     */
    public function setCustomerGroupIds($customer_group_ids)
    {
        if (is_null($customer_group_ids)) {
            throw new \InvalidArgumentException('non-nullable customer_group_ids cannot be null');
        }
        $this->container['customer_group_ids'] = $customer_group_ids;

        return $this;
    }

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

    /**
     * Sets description
     *
     * @param string|null $description A short description for the promotion.
     *
     * @return self
     */
    public function setDescription($description)
    {
        if (is_null($description)) {
            throw new \InvalidArgumentException('non-nullable description cannot be null');
        }
        $this->container['description'] = $description;

        return $this;
    }

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

    /**
     * Sets end_time
     *
     * @param string|null $end_time The time the promotion ends, in UTC, e.g. `2006-01-02T15:04:05`.
     *
     * @return self
     */
    public function setEndTime($end_time)
    {
        if (is_null($end_time)) {
            throw new \InvalidArgumentException('non-nullable end_time cannot be null');
        }
        $this->container['end_time'] = $end_time;

        return $this;
    }

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

    /**
     * Sets id
     *
     * @param string|null $id Auto-generated object 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 loyalty_multiplier
     *
     * @return float|null
     */
    public function getLoyaltyMultiplier()
    {
        return $this->container['loyalty_multiplier'];
    }

    /**
     * Sets loyalty_multiplier
     *
     * @param float|null $loyalty_multiplier The loyalty multiplier for the promotion.
     *
     * @return self
     */
    public function setLoyaltyMultiplier($loyalty_multiplier)
    {
        if (is_null($loyalty_multiplier)) {
            throw new \InvalidArgumentException('non-nullable loyalty_multiplier cannot be null');
        }
        $this->container['loyalty_multiplier'] = $loyalty_multiplier;

        return $this;
    }

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

    /**
     * Sets name
     *
     * @param string $name The name of the promotion.
     *
     * @return self
     */
    public function setName($name)
    {
        if (is_null($name)) {
            throw new \InvalidArgumentException('non-nullable name cannot be null');
        }
        $this->container['name'] = $name;

        return $this;
    }

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

    /**
     * Sets outlet_ids
     *
     * @param string[]|null $outlet_ids A list of outlet IDs for the promotion.
     *
     * @return self
     */
    public function setOutletIds($outlet_ids)
    {
        if (is_null($outlet_ids)) {
            throw new \InvalidArgumentException('non-nullable outlet_ids cannot be null');
        }
        $this->container['outlet_ids'] = $outlet_ids;

        return $this;
    }

    /**
     * Gets promo_code_summary
     *
     * @return \Vend\Model\PromotionPromoCodeSummary|null
     */
    public function getPromoCodeSummary()
    {
        return $this->container['promo_code_summary'];
    }

    /**
     * Sets promo_code_summary
     *
     * @param \Vend\Model\PromotionPromoCodeSummary|null $promo_code_summary promo_code_summary
     *
     * @return self
     */
    public function setPromoCodeSummary($promo_code_summary)
    {
        if (is_null($promo_code_summary)) {
            throw new \InvalidArgumentException('non-nullable promo_code_summary cannot be null');
        }
        $this->container['promo_code_summary'] = $promo_code_summary;

        return $this;
    }

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

    /**
     * Sets start_time
     *
     * @param string $start_time The time the promotion begins, in UTC, e.g. `2006-01-02T15:04:05`.
     *
     * @return self
     */
    public function setStartTime($start_time)
    {
        if (is_null($start_time)) {
            throw new \InvalidArgumentException('non-nullable start_time cannot be null');
        }
        $this->container['start_time'] = $start_time;

        return $this;
    }

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

    /**
     * Sets status
     *
     * @param string|null $status The status of the promotion.
     *
     * @return self
     */
    public function setStatus($status)
    {
        if (is_null($status)) {
            throw new \InvalidArgumentException('non-nullable status cannot be null');
        }
        $this->container['status'] = $status;

        return $this;
    }

    /**
     * Gets use_promo_code
     *
     * @return bool
     */
    public function getUsePromoCode()
    {
        return $this->container['use_promo_code'];
    }

    /**
     * Sets use_promo_code
     *
     * @param bool $use_promo_code Whether or not this promotion uses promo codes.
     *
     * @return self
     */
    public function setUsePromoCode($use_promo_code)
    {
        if (is_null($use_promo_code)) {
            throw new \InvalidArgumentException('non-nullable use_promo_code cannot be null');
        }
        $this->container['use_promo_code'] = $use_promo_code;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param integer|string $offset Offset
     *
     * @return boolean
     */
    public function offsetExists(mixed $offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param integer|string $offset Offset
     *
     * @return mixed|null
     */
    #[\ReturnTypeWillChange]
    public function offsetGet(mixed $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|string $offset Offset
     *
     * @return void
     */
    public function offsetUnset(mixed $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));
    }
}


