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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'approval_state' => 'int',
        'comments' => 'string',
        'cost_center' => 'string',
        'description' => 'string',
        'project' => 'string',
        'reference_number' => 'string',
        'reference_type' => 'string',
        'transaction_date' => '\DateTime',
        'voucher_number' => 'int',
        'voucher_rows' => '\Fortnox\Model\FortnoxBfVoucherRowSinglePayloadItem[]',
        'voucher_series' => 'string',
        'year' => 'int'
    ];

    /**
      * 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 = [
        'approval_state' => 'int32',
        'comments' => null,
        'cost_center' => null,
        'description' => null,
        'project' => null,
        'reference_number' => null,
        'reference_type' => null,
        'transaction_date' => 'date',
        'voucher_number' => 'int32',
        'voucher_rows' => null,
        'voucher_series' => null,
        'year' => 'int32'
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'approval_state' => false,
        'comments' => false,
        'cost_center' => false,
        'description' => false,
        'project' => false,
        'reference_number' => false,
        'reference_type' => false,
        'transaction_date' => false,
        'voucher_number' => false,
        'voucher_rows' => false,
        'voucher_series' => false,
        'year' => 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 = [
        'approval_state' => 'ApprovalState',
        'comments' => 'Comments',
        'cost_center' => 'CostCenter',
        'description' => 'Description',
        'project' => 'Project',
        'reference_number' => 'ReferenceNumber',
        'reference_type' => 'ReferenceType',
        'transaction_date' => 'TransactionDate',
        'voucher_number' => 'VoucherNumber',
        'voucher_rows' => 'VoucherRows',
        'voucher_series' => 'VoucherSeries',
        'year' => 'Year'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'approval_state' => 'setApprovalState',
        'comments' => 'setComments',
        'cost_center' => 'setCostCenter',
        'description' => 'setDescription',
        'project' => 'setProject',
        'reference_number' => 'setReferenceNumber',
        'reference_type' => 'setReferenceType',
        'transaction_date' => 'setTransactionDate',
        'voucher_number' => 'setVoucherNumber',
        'voucher_rows' => 'setVoucherRows',
        'voucher_series' => 'setVoucherSeries',
        'year' => 'setYear'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'approval_state' => 'getApprovalState',
        'comments' => 'getComments',
        'cost_center' => 'getCostCenter',
        'description' => 'getDescription',
        'project' => 'getProject',
        'reference_number' => 'getReferenceNumber',
        'reference_type' => 'getReferenceType',
        'transaction_date' => 'getTransactionDate',
        'voucher_number' => 'getVoucherNumber',
        'voucher_rows' => 'getVoucherRows',
        'voucher_series' => 'getVoucherSeries',
        'year' => 'getYear'
    ];

    /**
     * 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 REFERENCE_TYPE_INVOICE = 'INVOICE';
    public const REFERENCE_TYPE_SUPPLIERINVOICE = 'SUPPLIERINVOICE';
    public const REFERENCE_TYPE_INVOICEPAYMENT = 'INVOICEPAYMENT';
    public const REFERENCE_TYPE_SUPPLIERPAYMENT = 'SUPPLIERPAYMENT';
    public const REFERENCE_TYPE_MANUAL = 'MANUAL';
    public const REFERENCE_TYPE_CASHINVOICE = 'CASHINVOICE';
    public const REFERENCE_TYPE_ACCRUAL = 'ACCRUAL';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getReferenceTypeAllowableValues()
    {
        return [
            self::REFERENCE_TYPE_INVOICE,
            self::REFERENCE_TYPE_SUPPLIERINVOICE,
            self::REFERENCE_TYPE_INVOICEPAYMENT,
            self::REFERENCE_TYPE_SUPPLIERPAYMENT,
            self::REFERENCE_TYPE_MANUAL,
            self::REFERENCE_TYPE_CASHINVOICE,
            self::REFERENCE_TYPE_ACCRUAL,
        ];
    }

    /**
     * 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('approval_state', $data ?? [], null);
        $this->setIfExists('comments', $data ?? [], null);
        $this->setIfExists('cost_center', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('project', $data ?? [], null);
        $this->setIfExists('reference_number', $data ?? [], null);
        $this->setIfExists('reference_type', $data ?? [], null);
        $this->setIfExists('transaction_date', $data ?? [], null);
        $this->setIfExists('voucher_number', $data ?? [], null);
        $this->setIfExists('voucher_rows', $data ?? [], null);
        $this->setIfExists('voucher_series', $data ?? [], null);
        $this->setIfExists('year', $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['comments']) && (mb_strlen($this->container['comments']) > 1000)) {
            $invalidProperties[] = "invalid value for 'comments', the character length must be smaller than or equal to 1000.";
        }

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

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

        $allowedValues = $this->getReferenceTypeAllowableValues();
        if (!is_null($this->container['reference_type']) && !in_array($this->container['reference_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'reference_type', must be one of '%s'",
                $this->container['reference_type'],
                implode("', '", $allowedValues)
            );
        }

        if ($this->container['transaction_date'] === null) {
            $invalidProperties[] = "'transaction_date' can't be null";
        }
        if (!is_null($this->container['voucher_rows']) && (count($this->container['voucher_rows']) > 2147483647)) {
            $invalidProperties[] = "invalid value for 'voucher_rows', number of items must be less than or equal to 2147483647.";
        }

        if (!is_null($this->container['voucher_rows']) && (count($this->container['voucher_rows']) < 2)) {
            $invalidProperties[] = "invalid value for 'voucher_rows', number of items must be greater than or equal to 2.";
        }

        if ($this->container['voucher_series'] === null) {
            $invalidProperties[] = "'voucher_series' can't be null";
        }
        if ($this->container['year'] === null) {
            $invalidProperties[] = "'year' 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 approval_state
     *
     * @return int|null
     */
    public function getApprovalState()
    {
        return $this->container['approval_state'];
    }

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

        return $this;
    }

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

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets description
     *
     * @param string $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) > 200)) {
            throw new \InvalidArgumentException('invalid length for $description when calling FortnoxBfVoucherSinglePayloadItem., must be smaller than or equal to 200.');
        }
        if ((mb_strlen($description) < 1)) {
            throw new \InvalidArgumentException('invalid length for $description when calling FortnoxBfVoucherSinglePayloadItem., must be bigger than or equal to 1.');
        }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        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');
        }
        $allowedValues = $this->getReferenceTypeAllowableValues();
        if (!in_array($reference_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'reference_type', must be one of '%s'",
                    $reference_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['reference_type'] = $reference_type;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets voucher_rows
     *
     * @param \Fortnox\Model\FortnoxBfVoucherRowSinglePayloadItem[]|null $voucher_rows voucher_rows
     *
     * @return self
     */
    public function setVoucherRows($voucher_rows)
    {
        if (is_null($voucher_rows)) {
            throw new \InvalidArgumentException('non-nullable voucher_rows cannot be null');
        }

        if ((count($voucher_rows) > 2147483647)) {
            throw new \InvalidArgumentException('invalid value for $voucher_rows when calling FortnoxBfVoucherSinglePayloadItem., number of items must be less than or equal to 2147483647.');
        }
        if ((count($voucher_rows) < 2)) {
            throw new \InvalidArgumentException('invalid length for $voucher_rows when calling FortnoxBfVoucherSinglePayloadItem., number of items must be greater than or equal to 2.');
        }
        $this->container['voucher_rows'] = $voucher_rows;

        return $this;
    }

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

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

        return $this;
    }

    /**
     * Gets year
     *
     * @return int
     */
    public function getYear()
    {
        return $this->container['year'];
    }

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

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


