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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'construction_account' => 'int',
        'description' => 'string',
        'eu_account' => 'int',
        'euvat_account' => 'int',
        'eu_account' => 'int',
        'eu_vat_account' => 'int',
        'export_account' => 'int',
        'sales_account' => 'int',
        'vat' => 'float',
        'vat' => 'float'
    ];

    /**
      * 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 = [
        'construction_account' => 'int32',
        'description' => null,
        'eu_account' => 'int32',
        'euvat_account' => 'int32',
        'eu_account' => 'int32',
        'eu_vat_account' => 'int32',
        'export_account' => 'int32',
        'sales_account' => 'int32',
        'vat' => 'double',
        'vat' => 'float'
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'construction_account' => false,
        'description' => false,
        'eu_account' => false,
        'euvat_account' => false,
        'eu_account' => false,
        'eu_vat_account' => false,
        'export_account' => false,
        'sales_account' => false,
        'vat' => false,
        'vat' => 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 = [
        'construction_account' => 'ConstructionAccount',
        'description' => 'Description',
        'eu_account' => 'EUAccount',
        'euvat_account' => 'EUVATAccount',
        'eu_account' => 'EuAccount',
        'eu_vat_account' => 'EuVatAccount',
        'export_account' => 'ExportAccount',
        'sales_account' => 'SalesAccount',
        'vat' => 'VAT',
        'vat' => 'Vat'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'construction_account' => 'setConstructionAccount',
        'description' => 'setDescription',
        'eu_account' => 'setEuAccount',
        'euvat_account' => 'setEuvatAccount',
        'eu_account' => 'setEuAccount',
        'eu_vat_account' => 'setEuVatAccount',
        'export_account' => 'setExportAccount',
        'sales_account' => 'setSalesAccount',
        'vat' => 'setVat',
        'vat' => 'setVat'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'construction_account' => 'getConstructionAccount',
        'description' => 'getDescription',
        'eu_account' => 'getEuAccount',
        'euvat_account' => 'getEuvatAccount',
        'eu_account' => 'getEuAccount',
        'eu_vat_account' => 'getEuVatAccount',
        'export_account' => 'getExportAccount',
        'sales_account' => 'getSalesAccount',
        'vat' => 'getVat',
        'vat' => 'getVat'
    ];

    /**
     * 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('construction_account', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('eu_account', $data ?? [], null);
        $this->setIfExists('euvat_account', $data ?? [], null);
        $this->setIfExists('eu_account', $data ?? [], null);
        $this->setIfExists('eu_vat_account', $data ?? [], null);
        $this->setIfExists('export_account', $data ?? [], null);
        $this->setIfExists('sales_account', $data ?? [], null);
        $this->setIfExists('vat', $data ?? [], null);
        $this->setIfExists('vat', $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 (!is_null($this->container['construction_account']) && ($this->container['construction_account'] > 99999)) {
            $invalidProperties[] = "invalid value for 'construction_account', must be smaller than or equal to 99999.";
        }

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

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

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

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

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

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

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

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

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

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

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

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

        if (($construction_account > 99999)) {
            throw new \InvalidArgumentException('invalid value for $construction_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be smaller than or equal to 99999.');
        }
        if (($construction_account < 1000)) {
            throw new \InvalidArgumentException('invalid value for $construction_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be bigger than or equal to 1000.');
        }

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

        return $this;
    }

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

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

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

        return $this;
    }

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

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

        if (($eu_account > 99999)) {
            throw new \InvalidArgumentException('invalid value for $eu_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be smaller than or equal to 99999.');
        }
        if (($eu_account < 1000)) {
            throw new \InvalidArgumentException('invalid value for $eu_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be bigger than or equal to 1000.');
        }

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

        return $this;
    }

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

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

        if (($euvat_account > 99999)) {
            throw new \InvalidArgumentException('invalid value for $euvat_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be smaller than or equal to 99999.');
        }
        if (($euvat_account < 1000)) {
            throw new \InvalidArgumentException('invalid value for $euvat_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be bigger than or equal to 1000.');
        }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        if (($export_account > 99999)) {
            throw new \InvalidArgumentException('invalid value for $export_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be smaller than or equal to 99999.');
        }
        if (($export_account < 1000)) {
            throw new \InvalidArgumentException('invalid value for $export_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be bigger than or equal to 1000.');
        }

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

        return $this;
    }

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

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

        if (($sales_account > 99999)) {
            throw new \InvalidArgumentException('invalid value for $sales_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be smaller than or equal to 99999.');
        }
        if (($sales_account < 1000)) {
            throw new \InvalidArgumentException('invalid value for $sales_account when calling FortnoxArticleBundleSubItemRowSingleItem., must be bigger than or equal to 1000.');
        }

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

        return $this;
    }

    /**
     * Gets vat
     *
     * @return float|null
     */
    public function getVat()
    {
        return $this->container['vat'];
    }

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

        return $this;
    }

    /**
     * Gets vat
     *
     * @return float|null
     */
    public function getVat()
    {
        return $this->container['vat'];
    }

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

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


