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

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'article_registrations' => '\Fortnox\Model\TimeReportingArticleRegistration[]',
        'cost_center' => '\Fortnox\Model\TimeReportingTRCostCenter',
        'created_time' => '\DateTime',
        'customer' => '\Fortnox\Model\TimeReportingTRCustomer',
        'id' => 'string',
        'owner_id' => 'string',
        'project' => '\Fortnox\Model\TimeReportingTRProject',
        'purchase_date' => '\DateTime',
        'registered_article' => '\Fortnox\Model\TimeReportingArticleRegistration',
        'registration_type' => 'string',
        'version' => '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 = [
        'article_registrations' => null,
        'cost_center' => null,
        'created_time' => 'date-time',
        'customer' => null,
        'id' => 'uuid',
        'owner_id' => null,
        'project' => null,
        'purchase_date' => 'date',
        'registered_article' => null,
        'registration_type' => null,
        'version' => 'int64'
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'article_registrations' => false,
        'cost_center' => false,
        'created_time' => false,
        'customer' => false,
        'id' => false,
        'owner_id' => false,
        'project' => false,
        'purchase_date' => false,
        'registered_article' => false,
        'registration_type' => false,
        'version' => 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 = [
        'article_registrations' => 'articleRegistrations',
        'cost_center' => 'costCenter',
        'created_time' => 'createdTime',
        'customer' => 'customer',
        'id' => 'id',
        'owner_id' => 'ownerId',
        'project' => 'project',
        'purchase_date' => 'purchaseDate',
        'registered_article' => 'registeredArticle',
        'registration_type' => 'registrationType',
        'version' => 'version'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'article_registrations' => 'setArticleRegistrations',
        'cost_center' => 'setCostCenter',
        'created_time' => 'setCreatedTime',
        'customer' => 'setCustomer',
        'id' => 'setId',
        'owner_id' => 'setOwnerId',
        'project' => 'setProject',
        'purchase_date' => 'setPurchaseDate',
        'registered_article' => 'setRegisteredArticle',
        'registration_type' => 'setRegistrationType',
        'version' => 'setVersion'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'article_registrations' => 'getArticleRegistrations',
        'cost_center' => 'getCostCenter',
        'created_time' => 'getCreatedTime',
        'customer' => 'getCustomer',
        'id' => 'getId',
        'owner_id' => 'getOwnerId',
        'project' => 'getProject',
        'purchase_date' => 'getPurchaseDate',
        'registered_article' => 'getRegisteredArticle',
        'registration_type' => 'getRegistrationType',
        'version' => 'getVersion'
    ];

    /**
     * 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 REGISTRATION_TYPE_WORK = 'WORK';
    public const REGISTRATION_TYPE_ABSENCE = 'ABSENCE';
    public const REGISTRATION_TYPE_ARTICLE = 'ARTICLE';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getRegistrationTypeAllowableValues()
    {
        return [
            self::REGISTRATION_TYPE_WORK,
            self::REGISTRATION_TYPE_ABSENCE,
            self::REGISTRATION_TYPE_ARTICLE,
        ];
    }

    /**
     * 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('article_registrations', $data ?? [], null);
        $this->setIfExists('cost_center', $data ?? [], null);
        $this->setIfExists('created_time', $data ?? [], null);
        $this->setIfExists('customer', $data ?? [], null);
        $this->setIfExists('id', $data ?? [], null);
        $this->setIfExists('owner_id', $data ?? [], null);
        $this->setIfExists('project', $data ?? [], null);
        $this->setIfExists('purchase_date', $data ?? [], null);
        $this->setIfExists('registered_article', $data ?? [], null);
        $this->setIfExists('registration_type', $data ?? [], null);
        $this->setIfExists('version', $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['customer'] === null) {
            $invalidProperties[] = "'customer' can't be null";
        }
        if ($this->container['purchase_date'] === null) {
            $invalidProperties[] = "'purchase_date' can't be null";
        }
        $allowedValues = $this->getRegistrationTypeAllowableValues();
        if (!is_null($this->container['registration_type']) && !in_array($this->container['registration_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'registration_type', must be one of '%s'",
                $this->container['registration_type'],
                implode("', '", $allowedValues)
            );
        }

        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 article_registrations
     *
     * @return \Fortnox\Model\TimeReportingArticleRegistration[]|null
     */
    public function getArticleRegistrations()
    {
        return $this->container['article_registrations'];
    }

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

        return $this;
    }

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

    /**
     * Sets cost_center
     *
     * @param \Fortnox\Model\TimeReportingTRCostCenter|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 created_time
     *
     * @return \DateTime|null
     */
    public function getCreatedTime()
    {
        return $this->container['created_time'];
    }

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

        return $this;
    }

    /**
     * Gets customer
     *
     * @return \Fortnox\Model\TimeReportingTRCustomer
     */
    public function getCustomer()
    {
        return $this->container['customer'];
    }

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

        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');
        }
        $this->container['id'] = $id;

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets project
     *
     * @param \Fortnox\Model\TimeReportingTRProject|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 purchase_date
     *
     * @return \DateTime
     */
    public function getPurchaseDate()
    {
        return $this->container['purchase_date'];
    }

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

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

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

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


