<?php
/**
 * SubscriptionItem
 *
 * PHP version 7.3
 *
 * @category Class
 * @package  Pipedrive
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Pipedrive API v1
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.0.0
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 5.3.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 Pipedrive\Model;

use ArrayAccess;
use JsonException;
use JsonSerializable;
use Pipedrive\Traits\RawData;
use Pipedrive\ObjectSerializer;

/**
 * SubscriptionItem Class Doc Comment
 *
 * @category Class
 * @package  Pipedrive
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 * @implements ArrayAccess<TKey, TValue>
 * @template TKey int|null
 * @template TValue mixed|null
 */
class SubscriptionItem implements ModelInterface, ArrayAccess, JsonSerializable
{
    use RawData;

    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      * @phpstan-var array<string, string>
      * @phpsalm-var array<string, string>
      */
    protected static array $openAPITypes = [
        'id' => 'int',
        'user_id' => 'int',
        'deal_id' => 'int',
        'description' => 'string',
        'is_active' => 'bool',
        'cycles_count' => 'int',
        'cycle_amount' => 'int',
        'infinite' => 'bool',
        'currency' => 'string',
        'cadence_type' => 'string',
        'start_date' => '\DateTime',
        'end_date' => '\DateTime',
        'lifetime_value' => 'double',
        'final_status' => 'string',
        'add_time' => '\DateTime',
        'update_time' => '\DateTime'
    ];

    /**
      * 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 = [
        'id' => null,
        'user_id' => null,
        'deal_id' => null,
        'description' => null,
        'is_active' => null,
        'cycles_count' => null,
        'cycle_amount' => null,
        'infinite' => null,
        'currency' => null,
        'cadence_type' => null,
        'start_date' => 'date',
        'end_date' => 'date',
        'lifetime_value' => 'double',
        'final_status' => null,
        'add_time' => 'date-time',
        'update_time' => 'date-time'
    ];

    /**
     * Array of property to type mappings. Used for (de)serialization
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization
     *
     * @phpstan-return array<string, string|null>
     * @psalm-return array<string, string|null>
     * @return array
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @var string[]
     */
    protected static $attributeMap = [
        'id' => 'id',
        'user_id' => 'user_id',
        'deal_id' => 'deal_id',
        'description' => 'description',
        'is_active' => 'is_active',
        'cycles_count' => 'cycles_count',
        'cycle_amount' => 'cycle_amount',
        'infinite' => 'infinite',
        'currency' => 'currency',
        'cadence_type' => 'cadence_type',
        'start_date' => 'start_date',
        'end_date' => 'end_date',
        'lifetime_value' => 'lifetime_value',
        'final_status' => 'final_status',
        'add_time' => 'add_time',
        'update_time' => 'update_time'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'user_id' => 'setUserId',
        'deal_id' => 'setDealId',
        'description' => 'setDescription',
        'is_active' => 'setIsActive',
        'cycles_count' => 'setCyclesCount',
        'cycle_amount' => 'setCycleAmount',
        'infinite' => 'setInfinite',
        'currency' => 'setCurrency',
        'cadence_type' => 'setCadenceType',
        'start_date' => 'setStartDate',
        'end_date' => 'setEndDate',
        'lifetime_value' => 'setLifetimeValue',
        'final_status' => 'setFinalStatus',
        'add_time' => 'setAddTime',
        'update_time' => 'setUpdateTime'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'user_id' => 'getUserId',
        'deal_id' => 'getDealId',
        'description' => 'getDescription',
        'is_active' => 'getIsActive',
        'cycles_count' => 'getCyclesCount',
        'cycle_amount' => 'getCycleAmount',
        'infinite' => 'getInfinite',
        'currency' => 'getCurrency',
        'cadence_type' => 'getCadenceType',
        'start_date' => 'getStartDate',
        'end_date' => 'getEndDate',
        'lifetime_value' => 'getLifetimeValue',
        'final_status' => 'getFinalStatus',
        'add_time' => 'getAddTime',
        'update_time' => 'getUpdateTime'
    ];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @phpstan-return array<string, string>
     * @psalm-return array<string, string>
     * @return array
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     *
     * @return string
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }


    /**
     * Associative array for storing property values
     *
     * @var array
     * @phpstan-var array<int|string, mixed>
     * @psalm-var array<int|string, mixed>
     */
    protected array $container = [];

    /**
     * Constructor
     *
     * @phpstan-param array<string, mixed>|null $data
     * @psalm-param array<string, mixed>|null $data
     * @param array|null $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(array $data = null)
    {
        $this->container['id'] = $data['id'] ?? null;
        $this->container['user_id'] = $data['user_id'] ?? null;
        $this->container['deal_id'] = $data['deal_id'] ?? null;
        $this->container['description'] = $data['description'] ?? null;
        $this->container['is_active'] = $data['is_active'] ?? null;
        $this->container['cycles_count'] = $data['cycles_count'] ?? null;
        $this->container['cycle_amount'] = $data['cycle_amount'] ?? null;
        $this->container['infinite'] = $data['infinite'] ?? null;
        $this->container['currency'] = $data['currency'] ?? null;
        $this->container['cadence_type'] = $data['cadence_type'] ?? null;
        $this->container['start_date'] = $data['start_date'] ?? null;
        $this->container['end_date'] = $data['end_date'] ?? null;
        $this->container['lifetime_value'] = $data['lifetime_value'] ?? null;
        $this->container['final_status'] = $data['final_status'] ?? null;
        $this->container['add_time'] = $data['add_time'] ?? null;
        $this->container['update_time'] = $data['update_time'] ?? null;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     * @phpstan-return array<int, string>
     * @psalm-return array<int, string>
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        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(): bool
    {
        return count($this->listInvalidProperties()) === 0;
    }


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

    /**
     * Sets id
     *
     * @param int|null $id The ID of the subscription
     *
     * @return self
     */
    public function setId($id): self
    {
        $this->container['id'] = $id;

        return $this;
    }

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

    /**
     * Sets user_id
     *
     * @param int|null $user_id The ID of the user who created the subscription
     *
     * @return self
     */
    public function setUserId($user_id): self
    {
        $this->container['user_id'] = $user_id;

        return $this;
    }

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

    /**
     * Sets deal_id
     *
     * @param int|null $deal_id The ID of the deal this subscription is associated with
     *
     * @return self
     */
    public function setDealId($deal_id): self
    {
        $this->container['deal_id'] = $deal_id;

        return $this;
    }

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

    /**
     * Sets description
     *
     * @param string|null $description The description of the recurring subscription
     *
     * @return self
     */
    public function setDescription($description): self
    {
        $this->container['description'] = $description;

        return $this;
    }

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

    /**
     * Sets is_active
     *
     * @param bool|null $is_active The subscription status
     *
     * @return self
     */
    public function setIsActive($is_active): self
    {
        $this->container['is_active'] = $is_active;

        return $this;
    }

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

    /**
     * Sets cycles_count
     *
     * @param int|null $cycles_count Shows how many payments a recurring subscription has
     *
     * @return self
     */
    public function setCyclesCount($cycles_count): self
    {
        $this->container['cycles_count'] = $cycles_count;

        return $this;
    }

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

    /**
     * Sets cycle_amount
     *
     * @param int|null $cycle_amount The amount of each payment
     *
     * @return self
     */
    public function setCycleAmount($cycle_amount): self
    {
        $this->container['cycle_amount'] = $cycle_amount;

        return $this;
    }

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

    /**
     * Sets infinite
     *
     * @param bool|null $infinite Indicates that the recurring subscription will last until it is manually canceled or deleted
     *
     * @return self
     */
    public function setInfinite($infinite): self
    {
        $this->container['infinite'] = $infinite;

        return $this;
    }

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

    /**
     * Sets currency
     *
     * @param string|null $currency The currency of the subscription
     *
     * @return self
     */
    public function setCurrency($currency): self
    {
        $this->container['currency'] = $currency;

        return $this;
    }

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

    /**
     * Sets cadence_type
     *
     * @param string|null $cadence_type The interval between payments
     *
     * @return self
     */
    public function setCadenceType($cadence_type): self
    {
        $this->container['cadence_type'] = $cadence_type;

        return $this;
    }

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

    /**
     * Sets start_date
     *
     * @param \DateTime|null $start_date The start date of the recurring subscription
     *
     * @return self
     */
    public function setStartDate($start_date): self
    {
        $this->container['start_date'] = $start_date;

        return $this;
    }

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

    /**
     * Sets end_date
     *
     * @param \DateTime|null $end_date The end date of the subscription
     *
     * @return self
     */
    public function setEndDate($end_date): self
    {
        $this->container['end_date'] = $end_date;

        return $this;
    }

    /**
     * Gets lifetime_value
     *
     * @return double|null
     */
    public function getLifetimeValue()
    {
        return $this->container['lifetime_value'];
    }

    /**
     * Sets lifetime_value
     *
     * @param double|null $lifetime_value The total value of all payments
     *
     * @return self
     */
    public function setLifetimeValue($lifetime_value): self
    {
        $this->container['lifetime_value'] = $lifetime_value;

        return $this;
    }

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

    /**
     * Sets final_status
     *
     * @param string|null $final_status The final status of the subscription
     *
     * @return self
     */
    public function setFinalStatus($final_status): self
    {
        $this->container['final_status'] = $final_status;

        return $this;
    }

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

    /**
     * Sets add_time
     *
     * @param \DateTime|null $add_time The creation time of the subscription
     *
     * @return self
     */
    public function setAddTime($add_time): self
    {
        $this->container['add_time'] = $add_time;

        return $this;
    }

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

    /**
     * Sets update_time
     *
     * @param \DateTime|null $update_time The update time of the subscription
     *
     * @return self
     */
    public function setUpdateTime($update_time): self
    {
        $this->container['update_time'] = $update_time;

        return $this;
    }
    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param integer $offset Offset
     *
     * @return boolean
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param integer $offset Offset
     *
     * @return mixed
     */
    public function offsetGet($offset): mixed
    {
        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 $offset Offset
     *
     * @return void
     */
    public function offsetUnset($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.
     */
    public function jsonSerialize(): mixed
    {
       return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets the string presentation of the object
     *
     * @throws JsonException
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR
        );
    }

    /**
     * Gets a header-safe presentation of the object
     *
     * @throws JsonException
     * @return string
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this), JSON_THROW_ON_ERROR);
    }
}


