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

/**
 * Fortnox API
 *
 * # Documentation   The Fortnox API is organized around REST. This means that we’ve designed it to have resource-oriented URLs and be as predictable as possible for you as developer.  It also means that we use HTTP status codes when something goes wrong and HTTP verbs understod by many API clients around the web.  We use a modified version of OAuth2 for authentication to offer a secure way for both you and our users to interact.  The API is generally built to support both XML and JSON but in this documentation all the examples will be in JSON.  We encourage you to read all the articles in the [Guides & Good to Know section](https://www.fortnox.se/developer/guides-and-good-to-know/)</a> first, before going forward and learning about the different resources.  This to ensure you get an understanding of some of the shared components of the API such as parameters and error handling.  ## Rate limits  The limit per access-token is 25 requests per 5 seconds. This equals to 300 requests per minute.  [Read more about this here.](https://www.fortnox.se/developer/guides-and-good-to-know/rate-limits-for-fortnox-api/)  ## Query parameters  Use query parameters with the ?-character and separate parameters with the &-character.   **Example:**  GET - https://api.fortnox.se/3/invoices?accountnumberfrom=3000&accountnumberto=4000 Read more about our parameters [here](https://www.fortnox.se/developer/guides-and-good-to-know/parameters/)   Search the documentation using the search field in the top left corner.
 *
 * The version of the OpenAPI document: 
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.19.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 Fortnox\Model;

use \ArrayAccess;
use \Fortnox\ObjectSerializer;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'average_costs' => '\Fortnox\Model\WarehouseAverageCost[]',
        'date' => '\DateTime',
        'delivery_state' => 'string',
        'forced_delivery' => 'bool',
        'id' => 'string',
        'note' => 'string',
        'reference_type' => 'string',
        'rows' => '\Fortnox\Model\WarehouseCustomOutboundDocumentRow[]',
        'voided' => 'bool',
        'warehouse_ready' => '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 = [
        'average_costs' => null,
        'date' => 'date',
        'delivery_state' => null,
        'forced_delivery' => null,
        'id' => null,
        'note' => null,
        'reference_type' => null,
        'rows' => null,
        'voided' => null,
        'warehouse_ready' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'average_costs' => false,
        'date' => false,
        'delivery_state' => false,
        'forced_delivery' => false,
        'id' => false,
        'note' => false,
        'reference_type' => false,
        'rows' => false,
        'voided' => false,
        'warehouse_ready' => 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 = [
        'average_costs' => 'averageCosts',
        'date' => 'date',
        'delivery_state' => 'deliveryState',
        'forced_delivery' => 'forcedDelivery',
        'id' => 'id',
        'note' => 'note',
        'reference_type' => 'referenceType',
        'rows' => 'rows',
        'voided' => 'voided',
        'warehouse_ready' => 'warehouseReady'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'average_costs' => 'setAverageCosts',
        'date' => 'setDate',
        'delivery_state' => 'setDeliveryState',
        'forced_delivery' => 'setForcedDelivery',
        'id' => 'setId',
        'note' => 'setNote',
        'reference_type' => 'setReferenceType',
        'rows' => 'setRows',
        'voided' => 'setVoided',
        'warehouse_ready' => 'setWarehouseReady'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'average_costs' => 'getAverageCosts',
        'date' => 'getDate',
        'delivery_state' => 'getDeliveryState',
        'forced_delivery' => 'getForcedDelivery',
        'id' => 'getId',
        'note' => 'getNote',
        'reference_type' => 'getReferenceType',
        'rows' => 'getRows',
        'voided' => 'getVoided',
        'warehouse_ready' => 'getWarehouseReady'
    ];

    /**
     * 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 DELIVERY_STATE_REGISTRATION = 'registration';
    public const DELIVERY_STATE_RESERVATION = 'reservation';
    public const DELIVERY_STATE_DELIVERY = 'delivery';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getDeliveryStateAllowableValues()
    {
        return [
            self::DELIVERY_STATE_REGISTRATION,
            self::DELIVERY_STATE_RESERVATION,
            self::DELIVERY_STATE_DELIVERY,
        ];
    }

    /**
     * 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('average_costs', $data ?? [], null);
        $this->setIfExists('date', $data ?? [], null);
        $this->setIfExists('delivery_state', $data ?? [], null);
        $this->setIfExists('forced_delivery', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('note', $data ?? [], null);
        $this->setIfExists('reference_type', $data ?? [], null);
        $this->setIfExists('rows', $data ?? [], null);
        $this->setIfExists('voided', $data ?? [], null);
        $this->setIfExists('warehouse_ready', $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['date'] === null) {
            $invalidProperties[] = "'date' can't be null";
        }
        if ($this->container['delivery_state'] === null) {
            $invalidProperties[] = "'delivery_state' can't be null";
        }
        $allowedValues = $this->getDeliveryStateAllowableValues();
        if (!is_null($this->container['delivery_state']) && !in_array($this->container['delivery_state'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'delivery_state', must be one of '%s'",
                $this->container['delivery_state'],
                implode("', '", $allowedValues)
            );
        }

        if (!is_null($this->container['id']) && (mb_strlen($this->container['id']) > 25)) {
            $invalidProperties[] = "invalid value for 'id', the character length must be smaller than or equal to 25.";
        }

        if (!is_null($this->container['id']) && (mb_strlen($this->container['id']) < 1)) {
            $invalidProperties[] = "invalid value for 'id', the character length must be bigger than or equal to 1.";
        }

        if (!is_null($this->container['id']) && !preg_match("/^[0-9]+/", $this->container['id'])) {
            $invalidProperties[] = "invalid value for 'id', must be conform to the pattern /^[0-9]+/.";
        }

        if (!is_null($this->container['note']) && (mb_strlen($this->container['note']) > 1000)) {
            $invalidProperties[] = "invalid value for 'note', the character length must be smaller than or equal to 1000.";
        }

        if (!is_null($this->container['reference_type']) && (mb_strlen($this->container['reference_type']) > 25)) {
            $invalidProperties[] = "invalid value for 'reference_type', the character length must be smaller than or equal to 25.";
        }

        if (!is_null($this->container['reference_type']) && (mb_strlen($this->container['reference_type']) < 1)) {
            $invalidProperties[] = "invalid value for 'reference_type', the character length must be bigger than or equal to 1.";
        }

        if (!is_null($this->container['reference_type']) && !preg_match("/[a-zA-Z0-9_-]+/", $this->container['reference_type'])) {
            $invalidProperties[] = "invalid value for 'reference_type', must be conform to the pattern /[a-zA-Z0-9_-]+/.";
        }

        if ($this->container['rows'] === null) {
            $invalidProperties[] = "'rows' 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 average_costs
     *
     * @return \Fortnox\Model\WarehouseAverageCost[]|null
     */
    public function getAverageCosts()
    {
        return $this->container['average_costs'];
    }

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

        return $this;
    }

    /**
     * Gets date
     *
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->container['date'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets forced_delivery
     *
     * @return bool|null
     */
    public function getForcedDelivery()
    {
        return $this->container['forced_delivery'];
    }

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

        return $this;
    }

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

    /**
     * Sets id
     *
     * @param string|null $id id
     *
     * @return self
     */
    public function setId($id)
    {
        if (is_null($id)) {
            throw new \InvalidArgumentException('non-nullable id cannot be null');
        }
        if ((mb_strlen($id) > 25)) {
            throw new \InvalidArgumentException('invalid length for $id when calling WarehouseCustomOutboundDocument., must be smaller than or equal to 25.');
        }
        if ((mb_strlen($id) < 1)) {
            throw new \InvalidArgumentException('invalid length for $id when calling WarehouseCustomOutboundDocument., must be bigger than or equal to 1.');
        }
        if ((!preg_match("/^[0-9]+/", ObjectSerializer::toString($id)))) {
            throw new \InvalidArgumentException("invalid value for \$id when calling WarehouseCustomOutboundDocument., must conform to the pattern /^[0-9]+/.");
        }

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

        return $this;
    }

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

    /**
     * Sets note
     *
     * @param string|null $note note
     *
     * @return self
     */
    public function setNote($note)
    {
        if (is_null($note)) {
            throw new \InvalidArgumentException('non-nullable note cannot be null');
        }
        if ((mb_strlen($note) > 1000)) {
            throw new \InvalidArgumentException('invalid length for $note when calling WarehouseCustomOutboundDocument., must be smaller than or equal to 1000.');
        }

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

        return $this;
    }

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

    /**
     * Sets reference_type
     *
     * @param string|null $reference_type reference_type
     *
     * @return self
     */
    public function setReferenceType($reference_type)
    {
        if (is_null($reference_type)) {
            throw new \InvalidArgumentException('non-nullable reference_type cannot be null');
        }
        if ((mb_strlen($reference_type) > 25)) {
            throw new \InvalidArgumentException('invalid length for $reference_type when calling WarehouseCustomOutboundDocument., must be smaller than or equal to 25.');
        }
        if ((mb_strlen($reference_type) < 1)) {
            throw new \InvalidArgumentException('invalid length for $reference_type when calling WarehouseCustomOutboundDocument., must be bigger than or equal to 1.');
        }
        if ((!preg_match("/[a-zA-Z0-9_-]+/", ObjectSerializer::toString($reference_type)))) {
            throw new \InvalidArgumentException("invalid value for \$reference_type when calling WarehouseCustomOutboundDocument., must conform to the pattern /[a-zA-Z0-9_-]+/.");
        }

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

        return $this;
    }

    /**
     * Gets rows
     *
     * @return \Fortnox\Model\WarehouseCustomOutboundDocumentRow[]
     */
    public function getRows()
    {
        return $this->container['rows'];
    }

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

        return $this;
    }

    /**
     * Gets voided
     *
     * @return bool|null
     */
    public function getVoided()
    {
        return $this->container['voided'];
    }

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

        return $this;
    }

    /**
     * Gets warehouse_ready
     *
     * @return bool|null
     */
    public function getWarehouseReady()
    {
        return $this->container['warehouse_ready'];
    }

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

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


