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

/**
 * PaymentItem 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 PaymentItem implements ModelInterface, ArrayAccess, JsonSerializable
{
    use RawData;

    public const DISCRIMINATOR = null;

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

    /**
      * 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',
        'subscription_id' => 'int',
        'deal_id' => 'int',
        'is_active' => 'bool',
        'amount' => 'double',
        'currency' => 'string',
        'change_amount' => 'double',
        'due_at' => '\DateTime',
        'revenue_movement_type' => 'string',
        'payment_type' => 'string',
        'description' => '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,
        'subscription_id' => null,
        'deal_id' => null,
        'is_active' => null,
        'amount' => 'double',
        'currency' => null,
        'change_amount' => 'double',
        'due_at' => 'date',
        'revenue_movement_type' => null,
        'payment_type' => null,
        'description' => 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',
        'subscription_id' => 'subscription_id',
        'deal_id' => 'deal_id',
        'is_active' => 'is_active',
        'amount' => 'amount',
        'currency' => 'currency',
        'change_amount' => 'change_amount',
        'due_at' => 'due_at',
        'revenue_movement_type' => 'revenue_movement_type',
        'payment_type' => 'payment_type',
        'description' => 'description',
        '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',
        'subscription_id' => 'setSubscriptionId',
        'deal_id' => 'setDealId',
        'is_active' => 'setIsActive',
        'amount' => 'setAmount',
        'currency' => 'setCurrency',
        'change_amount' => 'setChangeAmount',
        'due_at' => 'setDueAt',
        'revenue_movement_type' => 'setRevenueMovementType',
        'payment_type' => 'setPaymentType',
        'description' => 'setDescription',
        'add_time' => 'setAddTime',
        'update_time' => 'setUpdateTime'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'subscription_id' => 'getSubscriptionId',
        'deal_id' => 'getDealId',
        'is_active' => 'getIsActive',
        'amount' => 'getAmount',
        'currency' => 'getCurrency',
        'change_amount' => 'getChangeAmount',
        'due_at' => 'getDueAt',
        'revenue_movement_type' => 'getRevenueMovementType',
        'payment_type' => 'getPaymentType',
        'description' => 'getDescription',
        '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;
    }

    const REVENUE_MOVEMENT_TYPE__NEW = 'new';
    const REVENUE_MOVEMENT_TYPE_RECURRING = 'recurring';
    const REVENUE_MOVEMENT_TYPE_EXPANSION = 'expansion';
    const REVENUE_MOVEMENT_TYPE_CONTRACTION = 'contraction';
    const REVENUE_MOVEMENT_TYPE_NONE = 'none';
    const REVENUE_MOVEMENT_TYPE_CHURN = 'churn';
    const PAYMENT_TYPE_RECURRING = 'recurring';
    const PAYMENT_TYPE_ADDITIONAL = 'additional';
    const PAYMENT_TYPE_INSTALLMENT = 'installment';

    /**
     * Gets allowable values of the enum
     *
     * @phpstan-return  array<string|int>
     * @phpsalm-return  array<string|int>
     * @return (string|int)[]
     */
    public function getRevenueMovementTypeAllowableValues(): array
    {
        return [
            self::REVENUE_MOVEMENT_TYPE__NEW,
            self::REVENUE_MOVEMENT_TYPE_RECURRING,
            self::REVENUE_MOVEMENT_TYPE_EXPANSION,
            self::REVENUE_MOVEMENT_TYPE_CONTRACTION,
            self::REVENUE_MOVEMENT_TYPE_NONE,
            self::REVENUE_MOVEMENT_TYPE_CHURN,
        ];
    }

    /**
     * Gets allowable values of the enum
     *
     * @phpstan-return  array<string|int>
     * @phpsalm-return  array<string|int>
     * @return (string|int)[]
     */
    public function getPaymentTypeAllowableValues(): array
    {
        return [
            self::PAYMENT_TYPE_RECURRING,
            self::PAYMENT_TYPE_ADDITIONAL,
            self::PAYMENT_TYPE_INSTALLMENT,
        ];
    }

    /**
     * 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['subscription_id'] = $data['subscription_id'] ?? null;
        $this->container['deal_id'] = $data['deal_id'] ?? null;
        $this->container['is_active'] = $data['is_active'] ?? null;
        $this->container['amount'] = $data['amount'] ?? null;
        $this->container['currency'] = $data['currency'] ?? null;
        $this->container['change_amount'] = $data['change_amount'] ?? null;
        $this->container['due_at'] = $data['due_at'] ?? null;
        $this->container['revenue_movement_type'] = $data['revenue_movement_type'] ?? null;
        $this->container['payment_type'] = $data['payment_type'] ?? null;
        $this->container['description'] = $data['description'] ?? 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 = [];

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

        $allowedValues = $this->getPaymentTypeAllowableValues();
        if (!is_null($this->container['payment_type']) && !in_array($this->container['payment_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'payment_type', must be one of '%s'",
                $this->container['payment_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(): 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 payment
     *
     * @return self
     */
    public function setId($id): self
    {
        $this->container['id'] = $id;

        return $this;
    }

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

    /**
     * Sets subscription_id
     *
     * @param int|null $subscription_id The ID of the subscription this payment is associated with
     *
     * @return self
     */
    public function setSubscriptionId($subscription_id): self
    {
        $this->container['subscription_id'] = $subscription_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 payment is associated with
     *
     * @return self
     */
    public function setDealId($deal_id): self
    {
        $this->container['deal_id'] = $deal_id;

        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 payment status
     *
     * @return self
     */
    public function setIsActive($is_active): self
    {
        $this->container['is_active'] = $is_active;

        return $this;
    }

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

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

        return $this;
    }

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

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

        return $this;
    }

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

    /**
     * Sets change_amount
     *
     * @param double|null $change_amount The difference between the amount of the current payment and the previous payment. The value can be either positive or negative.
     *
     * @return self
     */
    public function setChangeAmount($change_amount): self
    {
        $this->container['change_amount'] = $change_amount;

        return $this;
    }

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

    /**
     * Sets due_at
     *
     * @param \DateTime|null $due_at The date when payment occurs
     *
     * @return self
     */
    public function setDueAt($due_at): self
    {
        $this->container['due_at'] = $due_at;

        return $this;
    }

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

    /**
     * Sets revenue_movement_type
     *
     * @param string|null $revenue_movement_type Represents the movement of revenue in comparison with the previous payment. Possible values are: `New` - first payment of the subscription. `Recurring` - no movement. `Expansion` - current payment amount > previous payment amount. `Contraction` - current payment amount < previous payment amount. `Churn` - last payment of the subscription.
     *
     * @return self
     */
    public function setRevenueMovementType($revenue_movement_type): self
    {
        $allowedValues = $this->getRevenueMovementTypeAllowableValues();
        if (!is_null($revenue_movement_type) && !in_array($revenue_movement_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'revenue_movement_type', must be one of '%s'",
                    $revenue_movement_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['revenue_movement_type'] = $revenue_movement_type;

        return $this;
    }

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

    /**
     * Sets payment_type
     *
     * @param string|null $payment_type The type of the payment. Possible values are: `Recurring` - payments occur over fixed intervals of time, `Additional` - extra payment not the recurring payment of the recurring subscription, `Installment` - payment of the installment subscription.
     *
     * @return self
     */
    public function setPaymentType($payment_type): self
    {
        $allowedValues = $this->getPaymentTypeAllowableValues();
        if (!is_null($payment_type) && !in_array($payment_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'payment_type', must be one of '%s'",
                    $payment_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['payment_type'] = $payment_type;

        return $this;
    }

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

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

        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 payment
     *
     * @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 payment
     *
     * @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);
    }
}


