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

/**
 * FulfillmentHistoryEntry Class Doc Comment
 *
 * @category Class
 * @description A single state-change event in the fulfillment history ledger
 * @package  Vend
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements \ArrayAccess<string, mixed>
 */
class FulfillmentHistoryEntry implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @var string[]
     */
    protected static $openAPITypes = [
        'created_at' => '\DateTime',
        'event_type' => 'string',
        'fulfilled_delta' => 'string',
        'packed_quantity_delta' => 'string',
        'picked_quantity_delta' => 'string',
        'product_id' => 'string',
        'quantity_delta' => 'string',
        'sale_line_item_id' => 'string',
        'source_sale_id' => '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 = [
        'created_at' => 'date-time',
        'event_type' => null,
        'fulfilled_delta' => null,
        'packed_quantity_delta' => null,
        'picked_quantity_delta' => null,
        'product_id' => 'uuid',
        'quantity_delta' => null,
        'sale_line_item_id' => 'uuid',
        'source_sale_id' => 'uuid'
    ];

    /**
     * Array of nullable properties. Used for (de)serialization
     *
     * @var boolean[]
     */
    protected static array $openAPINullables = [
        'created_at' => false,
        'event_type' => false,
        'fulfilled_delta' => false,
        'packed_quantity_delta' => false,
        'picked_quantity_delta' => false,
        'product_id' => false,
        'quantity_delta' => false,
        'sale_line_item_id' => false,
        'source_sale_id' => 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 = [
        'created_at' => 'created_at',
        'event_type' => 'event_type',
        'fulfilled_delta' => 'fulfilled_delta',
        'packed_quantity_delta' => 'packed_quantity_delta',
        'picked_quantity_delta' => 'picked_quantity_delta',
        'product_id' => 'product_id',
        'quantity_delta' => 'quantity_delta',
        'sale_line_item_id' => 'sale_line_item_id',
        'source_sale_id' => 'source_sale_id'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'created_at' => 'setCreatedAt',
        'event_type' => 'setEventType',
        'fulfilled_delta' => 'setFulfilledDelta',
        'packed_quantity_delta' => 'setPackedQuantityDelta',
        'picked_quantity_delta' => 'setPickedQuantityDelta',
        'product_id' => 'setProductId',
        'quantity_delta' => 'setQuantityDelta',
        'sale_line_item_id' => 'setSaleLineItemId',
        'source_sale_id' => 'setSourceSaleId'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'created_at' => 'getCreatedAt',
        'event_type' => 'getEventType',
        'fulfilled_delta' => 'getFulfilledDelta',
        'packed_quantity_delta' => 'getPackedQuantityDelta',
        'picked_quantity_delta' => 'getPickedQuantityDelta',
        'product_id' => 'getProductId',
        'quantity_delta' => 'getQuantityDelta',
        'sale_line_item_id' => 'getSaleLineItemId',
        'source_sale_id' => 'getSourceSaleId'
    ];

    /**
     * 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 EVENT_TYPE_CREATED = 'CREATED';
    public const EVENT_TYPE_QUANTITY_UPDATED = 'QUANTITY_UPDATED';
    public const EVENT_TYPE_REMOVED = 'REMOVED';
    public const EVENT_TYPE_PICKED = 'PICKED';
    public const EVENT_TYPE_PACKED = 'PACKED';
    public const EVENT_TYPE_FULFILLED = 'FULFILLED';
    public const EVENT_TYPE_VOIDED = 'VOIDED';
    public const EVENT_TYPE_UNVOIDED = 'UNVOIDED';
    public const EVENT_TYPE_RETURNED = 'RETURNED';
    public const EVENT_TYPE_RETURN_VOIDED = 'RETURN_VOIDED';
    public const EVENT_TYPE_SPLIT = 'SPLIT';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getEventTypeAllowableValues()
    {
        return [
            self::EVENT_TYPE_CREATED,
            self::EVENT_TYPE_QUANTITY_UPDATED,
            self::EVENT_TYPE_REMOVED,
            self::EVENT_TYPE_PICKED,
            self::EVENT_TYPE_PACKED,
            self::EVENT_TYPE_FULFILLED,
            self::EVENT_TYPE_VOIDED,
            self::EVENT_TYPE_UNVOIDED,
            self::EVENT_TYPE_RETURNED,
            self::EVENT_TYPE_RETURN_VOIDED,
            self::EVENT_TYPE_SPLIT,
        ];
    }

    /**
     * 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('created_at', $data ?? [], null);
        $this->setIfExists('event_type', $data ?? [], null);
        $this->setIfExists('fulfilled_delta', $data ?? [], null);
        $this->setIfExists('packed_quantity_delta', $data ?? [], null);
        $this->setIfExists('picked_quantity_delta', $data ?? [], null);
        $this->setIfExists('product_id', $data ?? [], null);
        $this->setIfExists('quantity_delta', $data ?? [], null);
        $this->setIfExists('sale_line_item_id', $data ?? [], null);
        $this->setIfExists('source_sale_id', $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['created_at'] === null) {
            $invalidProperties[] = "'created_at' can't be null";
        }
        if ($this->container['event_type'] === null) {
            $invalidProperties[] = "'event_type' can't be null";
        }
        $allowedValues = $this->getEventTypeAllowableValues();
        if (!is_null($this->container['event_type']) && !in_array($this->container['event_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'event_type', must be one of '%s'",
                $this->container['event_type'],
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['fulfilled_delta'] === null) {
            $invalidProperties[] = "'fulfilled_delta' can't be null";
        }
        if ($this->container['packed_quantity_delta'] === null) {
            $invalidProperties[] = "'packed_quantity_delta' can't be null";
        }
        if ($this->container['picked_quantity_delta'] === null) {
            $invalidProperties[] = "'picked_quantity_delta' can't be null";
        }
        if ($this->container['product_id'] === null) {
            $invalidProperties[] = "'product_id' can't be null";
        }
        if ($this->container['quantity_delta'] === null) {
            $invalidProperties[] = "'quantity_delta' can't be null";
        }
        if ($this->container['sale_line_item_id'] === null) {
            $invalidProperties[] = "'sale_line_item_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 created_at
     *
     * @return \DateTime
     */
    public function getCreatedAt()
    {
        return $this->container['created_at'];
    }

    /**
     * Sets created_at
     *
     * @param \DateTime $created_at Timestamp when the event was recorded
     *
     * @return self
     */
    public function setCreatedAt($created_at)
    {
        if (is_null($created_at)) {
            throw new \InvalidArgumentException('non-nullable created_at cannot be null');
        }
        $this->container['created_at'] = $created_at;

        return $this;
    }

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

    /**
     * Sets event_type
     *
     * @param string $event_type The type of state-change event
     *
     * @return self
     */
    public function setEventType($event_type)
    {
        if (is_null($event_type)) {
            throw new \InvalidArgumentException('non-nullable event_type cannot be null');
        }
        $allowedValues = $this->getEventTypeAllowableValues();
        if (!in_array($event_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'event_type', must be one of '%s'",
                    $event_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['event_type'] = $event_type;

        return $this;
    }

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

    /**
     * Sets fulfilled_delta
     *
     * @param string $fulfilled_delta Change in fulfilled quantity for this line item
     *
     * @return self
     */
    public function setFulfilledDelta($fulfilled_delta)
    {
        if (is_null($fulfilled_delta)) {
            throw new \InvalidArgumentException('non-nullable fulfilled_delta cannot be null');
        }
        $this->container['fulfilled_delta'] = $fulfilled_delta;

        return $this;
    }

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

    /**
     * Sets packed_quantity_delta
     *
     * @param string $packed_quantity_delta Change in packed quantity for this line item
     *
     * @return self
     */
    public function setPackedQuantityDelta($packed_quantity_delta)
    {
        if (is_null($packed_quantity_delta)) {
            throw new \InvalidArgumentException('non-nullable packed_quantity_delta cannot be null');
        }
        $this->container['packed_quantity_delta'] = $packed_quantity_delta;

        return $this;
    }

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

    /**
     * Sets picked_quantity_delta
     *
     * @param string $picked_quantity_delta Change in picked quantity for this line item
     *
     * @return self
     */
    public function setPickedQuantityDelta($picked_quantity_delta)
    {
        if (is_null($picked_quantity_delta)) {
            throw new \InvalidArgumentException('non-nullable picked_quantity_delta cannot be null');
        }
        $this->container['picked_quantity_delta'] = $picked_quantity_delta;

        return $this;
    }

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

    /**
     * Sets product_id
     *
     * @param string $product_id The ID of the product associated with the line item
     *
     * @return self
     */
    public function setProductId($product_id)
    {
        if (is_null($product_id)) {
            throw new \InvalidArgumentException('non-nullable product_id cannot be null');
        }
        $this->container['product_id'] = $product_id;

        return $this;
    }

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

    /**
     * Sets quantity_delta
     *
     * @param string $quantity_delta Change in total quantity for this line item
     *
     * @return self
     */
    public function setQuantityDelta($quantity_delta)
    {
        if (is_null($quantity_delta)) {
            throw new \InvalidArgumentException('non-nullable quantity_delta cannot be null');
        }
        $this->container['quantity_delta'] = $quantity_delta;

        return $this;
    }

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

    /**
     * Sets sale_line_item_id
     *
     * @param string $sale_line_item_id The ID of the sale line item this event relates to
     *
     * @return self
     */
    public function setSaleLineItemId($sale_line_item_id)
    {
        if (is_null($sale_line_item_id)) {
            throw new \InvalidArgumentException('non-nullable sale_line_item_id cannot be null');
        }
        $this->container['sale_line_item_id'] = $sale_line_item_id;

        return $this;
    }

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

    /**
     * Sets source_sale_id
     *
     * @param string|null $source_sale_id The ID of the source sale (present for RETURNED and SPLIT events)
     *
     * @return self
     */
    public function setSourceSaleId($source_sale_id)
    {
        if (is_null($source_sale_id)) {
            throw new \InvalidArgumentException('non-nullable source_sale_id cannot be null');
        }
        $this->container['source_sale_id'] = $source_sale_id;

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


