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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'cost_center_code' => 'string',
        'date' => '\DateTime',
        'id' => 'int',
        'name' => 'string',
        'project_id' => 'string',
        'responsible' => 'string',
        'rows' => '\Fortnox\Model\WarehouseStockTakingRow[]',
        'sort_params' => '\Fortnox\Model\WarehouseStockTakingSortParams',
        'sorting_id' => 'int',
        'state' => 'string',
        'using_stock_points' => '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 = [
        'cost_center_code' => null,
        'date' => 'date',
        'id' => 'int64',
        'name' => null,
        'project_id' => null,
        'responsible' => null,
        'rows' => null,
        'sort_params' => null,
        'sorting_id' => 'int32',
        'state' => null,
        'using_stock_points' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'cost_center_code' => false,
        'date' => false,
        'id' => false,
        'name' => false,
        'project_id' => false,
        'responsible' => false,
        'rows' => false,
        'sort_params' => false,
        'sorting_id' => false,
        'state' => false,
        'using_stock_points' => 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 = [
        'cost_center_code' => 'costCenterCode',
        'date' => 'date',
        'id' => 'id',
        'name' => 'name',
        'project_id' => 'projectId',
        'responsible' => 'responsible',
        'rows' => 'rows',
        'sort_params' => 'sortParams',
        'sorting_id' => 'sortingId',
        'state' => 'state',
        'using_stock_points' => 'usingStockPoints'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'cost_center_code' => 'setCostCenterCode',
        'date' => 'setDate',
        'id' => 'setId',
        'name' => 'setName',
        'project_id' => 'setProjectId',
        'responsible' => 'setResponsible',
        'rows' => 'setRows',
        'sort_params' => 'setSortParams',
        'sorting_id' => 'setSortingId',
        'state' => 'setState',
        'using_stock_points' => 'setUsingStockPoints'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'cost_center_code' => 'getCostCenterCode',
        'date' => 'getDate',
        'id' => 'getId',
        'name' => 'getName',
        'project_id' => 'getProjectId',
        'responsible' => 'getResponsible',
        'rows' => 'getRows',
        'sort_params' => 'getSortParams',
        'sorting_id' => 'getSortingId',
        'state' => 'getState',
        'using_stock_points' => 'getUsingStockPoints'
    ];

    /**
     * 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('cost_center_code', $data ?? [], null);
        $this->setIfExists('date', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('project_id', $data ?? [], null);
        $this->setIfExists('responsible', $data ?? [], null);
        $this->setIfExists('rows', $data ?? [], null);
        $this->setIfExists('sort_params', $data ?? [], null);
        $this->setIfExists('sorting_id', $data ?? [], null);
        $this->setIfExists('state', $data ?? [], null);
        $this->setIfExists('using_stock_points', $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['name'] === null) {
            $invalidProperties[] = "'name' can't be null";
        }
        if ((mb_strlen($this->container['name']) > 50)) {
            $invalidProperties[] = "invalid value for 'name', the character length must be smaller than or equal to 50.";
        }

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

        if ($this->container['responsible'] === null) {
            $invalidProperties[] = "'responsible' can't be null";
        }
        if ((mb_strlen($this->container['responsible']) > 50)) {
            $invalidProperties[] = "invalid value for 'responsible', the character length must be smaller than or equal to 50.";
        }

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

        if ($this->container['state'] === null) {
            $invalidProperties[] = "'state' can't be null";
        }
        if (!preg_match("/planning|started|completed|voided/", $this->container['state'])) {
            $invalidProperties[] = "invalid value for 'state', must be conform to the pattern /planning|started|completed|voided/.";
        }

        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 cost_center_code
     *
     * @return string|null
     */
    public function getCostCenterCode()
    {
        return $this->container['cost_center_code'];
    }

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

        return $this;
    }

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

    /**
     * Sets date
     *
     * @param \DateTime|null $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 id
     *
     * @return int|null
     */
    public function getId()
    {
        return $this->container['id'];
    }

    /**
     * Sets id
     *
     * @param int|null $id 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 name
     *
     * @return string
     */
    public function getName()
    {
        return $this->container['name'];
    }

    /**
     * Sets name
     *
     * @param string $name name
     *
     * @return self
     */
    public function setName($name)
    {
        if (is_null($name)) {
            throw new \InvalidArgumentException('non-nullable name cannot be null');
        }
        if ((mb_strlen($name) > 50)) {
            throw new \InvalidArgumentException('invalid length for $name when calling WarehouseStockTaking., must be smaller than or equal to 50.');
        }
        if ((mb_strlen($name) < 1)) {
            throw new \InvalidArgumentException('invalid length for $name when calling WarehouseStockTaking., must be bigger than or equal to 1.');
        }

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets responsible
     *
     * @param string $responsible responsible
     *
     * @return self
     */
    public function setResponsible($responsible)
    {
        if (is_null($responsible)) {
            throw new \InvalidArgumentException('non-nullable responsible cannot be null');
        }
        if ((mb_strlen($responsible) > 50)) {
            throw new \InvalidArgumentException('invalid length for $responsible when calling WarehouseStockTaking., must be smaller than or equal to 50.');
        }
        if ((mb_strlen($responsible) < 1)) {
            throw new \InvalidArgumentException('invalid length for $responsible when calling WarehouseStockTaking., must be bigger than or equal to 1.');
        }

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

        return $this;
    }

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

    /**
     * Sets rows
     *
     * @param \Fortnox\Model\WarehouseStockTakingRow[]|null $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 sort_params
     *
     * @return \Fortnox\Model\WarehouseStockTakingSortParams|null
     */
    public function getSortParams()
    {
        return $this->container['sort_params'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets state
     *
     * @param string $state state
     *
     * @return self
     */
    public function setState($state)
    {
        if (is_null($state)) {
            throw new \InvalidArgumentException('non-nullable state cannot be null');
        }

        if ((!preg_match("/planning|started|completed|voided/", ObjectSerializer::toString($state)))) {
            throw new \InvalidArgumentException("invalid value for \$state when calling WarehouseStockTaking., must conform to the pattern /planning|started|completed|voided/.");
        }

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

        return $this;
    }

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

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

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


