<?php

/**
 * Legal Entity Management API
 *
 * The version of the OpenAPI document: 4
 * Generated by: https://openapi-generator.tech
 * OpenAPI Generator version: 6.0.1
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Adyen\Model\LegalEntityManagement;

use ArrayAccess;
use Adyen\Model\LegalEntityManagement\ObjectSerializer;

/**
 * SourceOfFunds Class Doc Comment
 *
 * @package  Adyen
 * @implements ArrayAccess<string, mixed>
 */
class SourceOfFunds implements ModelInterface, ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'adyenProcessedFunds' => 'bool',
        'amount' => '\Adyen\Model\LegalEntityManagement\Amount',
        'assetMonthsHeld' => 'int',
        'cryptocurrencyExchange' => 'string',
        'dateOfFundsReceived' => '\DateTime',
        'dateOfSourceEvent' => '\DateTime',
        'description' => 'string',
        'financiers' => '\Adyen\Model\LegalEntityManagement\Financier[]',
        'originatorLegalEntityId' => 'string',
        'purpose' => 'string',
        'relationship' => 'string',
        'type' => 'string',
        'website' => 'string'
    ];

    /**
      * 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 = [
        'adyenProcessedFunds' => null,
        'amount' => null,
        'assetMonthsHeld' => 'int32',
        'cryptocurrencyExchange' => null,
        'dateOfFundsReceived' => 'date',
        'dateOfSourceEvent' => 'date',
        'description' => null,
        'financiers' => null,
        'originatorLegalEntityId' => null,
        'purpose' => null,
        'relationship' => null,
        'type' => null,
        'website' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static $openAPINullables = [
        'adyenProcessedFunds' => false,
        'amount' => false,
        'assetMonthsHeld' => true,
        'cryptocurrencyExchange' => false,
        'dateOfFundsReceived' => false,
        'dateOfSourceEvent' => false,
        'description' => false,
        'financiers' => false,
        'originatorLegalEntityId' => false,
        'purpose' => false,
        'relationship' => false,
        'type' => false,
        'website' => false
    ];

    /**
      * If a nullable field gets set to null, insert it here
      *
      * @var boolean[]
      */
    protected $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 = [
        'adyenProcessedFunds' => 'adyenProcessedFunds',
        'amount' => 'amount',
        'assetMonthsHeld' => 'assetMonthsHeld',
        'cryptocurrencyExchange' => 'cryptocurrencyExchange',
        'dateOfFundsReceived' => 'dateOfFundsReceived',
        'dateOfSourceEvent' => 'dateOfSourceEvent',
        'description' => 'description',
        'financiers' => 'financiers',
        'originatorLegalEntityId' => 'originatorLegalEntityId',
        'purpose' => 'purpose',
        'relationship' => 'relationship',
        'type' => 'type',
        'website' => 'website'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'adyenProcessedFunds' => 'setAdyenProcessedFunds',
        'amount' => 'setAmount',
        'assetMonthsHeld' => 'setAssetMonthsHeld',
        'cryptocurrencyExchange' => 'setCryptocurrencyExchange',
        'dateOfFundsReceived' => 'setDateOfFundsReceived',
        'dateOfSourceEvent' => 'setDateOfSourceEvent',
        'description' => 'setDescription',
        'financiers' => 'setFinanciers',
        'originatorLegalEntityId' => 'setOriginatorLegalEntityId',
        'purpose' => 'setPurpose',
        'relationship' => 'setRelationship',
        'type' => 'setType',
        'website' => 'setWebsite'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'adyenProcessedFunds' => 'getAdyenProcessedFunds',
        'amount' => 'getAmount',
        'assetMonthsHeld' => 'getAssetMonthsHeld',
        'cryptocurrencyExchange' => 'getCryptocurrencyExchange',
        'dateOfFundsReceived' => 'getDateOfFundsReceived',
        'dateOfSourceEvent' => 'getDateOfSourceEvent',
        'description' => 'getDescription',
        'financiers' => 'getFinanciers',
        'originatorLegalEntityId' => 'getOriginatorLegalEntityId',
        'purpose' => 'getPurpose',
        'relationship' => 'getRelationship',
        'type' => 'getType',
        'website' => 'getWebsite'
    ];

    /**
     * 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 TYPE_BUSINESS = 'business';
    public const TYPE_EMPLOYMENT = 'employment';
    public const TYPE_DONATIONS = 'donations';
    public const TYPE_INHERITANCE = 'inheritance';
    public const TYPE_FINANCIAL_AID = 'financialAid';
    public const TYPE_RENTAL_INCOME = 'rentalIncome';
    public const TYPE_DIVIDEND_INCOME = 'dividendIncome';
    public const TYPE_ROYALTY_INCOME = 'royaltyIncome';
    public const TYPE_THIRD_PARTY_FUNDING = 'thirdPartyFunding';
    public const TYPE_PENSION_INCOME = 'pensionIncome';
    public const TYPE_INSURANCE_SETTLEMENT = 'insuranceSettlement';
    public const TYPE_CRYPTOCURRENCY_INCOME = 'cryptocurrencyIncome';
    public const TYPE_ASSET_SALE = 'assetSale';
    public const TYPE_LOANS = 'loans';
    public const TYPE_GAMBLING_WINNINGS = 'gamblingWinnings';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getTypeAllowableValues()
    {
        return [
            self::TYPE_BUSINESS,
            self::TYPE_EMPLOYMENT,
            self::TYPE_DONATIONS,
            self::TYPE_INHERITANCE,
            self::TYPE_FINANCIAL_AID,
            self::TYPE_RENTAL_INCOME,
            self::TYPE_DIVIDEND_INCOME,
            self::TYPE_ROYALTY_INCOME,
            self::TYPE_THIRD_PARTY_FUNDING,
            self::TYPE_PENSION_INCOME,
            self::TYPE_INSURANCE_SETTLEMENT,
            self::TYPE_CRYPTOCURRENCY_INCOME,
            self::TYPE_ASSET_SALE,
            self::TYPE_LOANS,
            self::TYPE_GAMBLING_WINNINGS,
        ];
    }
    /**
     * Associative array for storing property values
     *
     * @var mixed[]
     */
    protected $container = [];

    /**
     * Constructor
     *
     * @param mixed[] $data Associated array of property values
     *                      initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('adyenProcessedFunds', $data ?? [], null);
        $this->setIfExists('amount', $data ?? [], null);
        $this->setIfExists('assetMonthsHeld', $data ?? [], null);
        $this->setIfExists('cryptocurrencyExchange', $data ?? [], null);
        $this->setIfExists('dateOfFundsReceived', $data ?? [], null);
        $this->setIfExists('dateOfSourceEvent', $data ?? [], null);
        $this->setIfExists('description', $data ?? [], null);
        $this->setIfExists('financiers', $data ?? [], null);
        $this->setIfExists('originatorLegalEntityId', $data ?? [], null);
        $this->setIfExists('purpose', $data ?? [], null);
        $this->setIfExists('relationship', $data ?? [], null);
        $this->setIfExists('type', $data ?? [], null);
        $this->setIfExists('website', $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['adyenProcessedFunds'] === null) {
            $invalidProperties[] = "'adyenProcessedFunds' can't be null";
        }
        $allowedValues = $this->getTypeAllowableValues();
        if (!is_null($this->container['type']) && !in_array($this->container['type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'type', must be one of '%s'",
                $this->container['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 adyenProcessedFunds
     *
     * @return bool
     */
    public function getAdyenProcessedFunds()
    {
        return $this->container['adyenProcessedFunds'];
    }

    /**
     * Sets adyenProcessedFunds
     *
     * @param bool $adyenProcessedFunds Indicates whether the funds are coming from transactions processed by Adyen. If **false**, the `type` is required.
     *
     * @return self
     */
    public function setAdyenProcessedFunds($adyenProcessedFunds)
    {
        $this->container['adyenProcessedFunds'] = $adyenProcessedFunds;

        return $this;
    }

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

    /**
     * Sets amount
     *
     * @param \Adyen\Model\LegalEntityManagement\Amount|null $amount amount
     *
     * @return self
     */
    public function setAmount($amount)
    {
        $this->container['amount'] = $amount;

        return $this;
    }

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

    /**
     * Sets assetMonthsHeld
     *
     * @param int|null $assetMonthsHeld The number of months that the asset has been in possession of the user.  For example, if the source of funds is of type **cryptocurrencyIncome** then `assetMonthsHeld` is the number of months the user has owned the cryptocurrency.
     *
     * @return self
     */
    public function setAssetMonthsHeld($assetMonthsHeld)
    {
        $this->container['assetMonthsHeld'] = $assetMonthsHeld;

        return $this;
    }

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

    /**
     * Sets cryptocurrencyExchange
     *
     * @param string|null $cryptocurrencyExchange Required if `type` is **cryptocurrencyIncome**. The cryptocurrency exchange where the funds were acquired.
     *
     * @return self
     */
    public function setCryptocurrencyExchange($cryptocurrencyExchange)
    {
        $this->container['cryptocurrencyExchange'] = $cryptocurrencyExchange;

        return $this;
    }

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

    /**
     * Sets dateOfFundsReceived
     *
     * @param \DateTime|null $dateOfFundsReceived Required if `type` is **donations** or **inheritance**. The date the funds were received, in YYYY-MM-DD format.
     *
     * @return self
     */
    public function setDateOfFundsReceived($dateOfFundsReceived)
    {
        $this->container['dateOfFundsReceived'] = $dateOfFundsReceived;

        return $this;
    }

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

    /**
     * Sets dateOfSourceEvent
     *
     * @param \DateTime|null $dateOfSourceEvent Required if `type` is **assetSale** or **gamblingWinnings**. The date the funds were received, in YYYY-MM-DD format.  For example, if the source of funds is of type **assetSale**, the dateOfSourceEvent is the date of the sale. If the source of funds is of type **gamblingWinnings**, the dateOfSourceEvent is the date of winnings.
     *
     * @return self
     */
    public function setDateOfSourceEvent($dateOfSourceEvent)
    {
        $this->container['dateOfSourceEvent'] = $dateOfSourceEvent;

        return $this;
    }

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

    /**
     * Sets description
     *
     * @param string|null $description Required if `type` is **business** or **assetSale**. A description for the source of funds.  For example, for `type` **business**, provide a description of where the business transactions come from, such as payments through bank transfer. For `type` **assetSale**, provide a description of the asset. For example, the address of a residential property if it is a property sale.
     *
     * @return self
     */
    public function setDescription($description)
    {
        $this->container['description'] = $description;

        return $this;
    }

    /**
     * Gets financiers
     *
     * @return \Adyen\Model\LegalEntityManagement\Financier[]|null
     */
    public function getFinanciers()
    {
        return $this->container['financiers'];
    }

    /**
     * Sets financiers
     *
     * @param \Adyen\Model\LegalEntityManagement\Financier[]|null $financiers Required if `type` is **thirdPartyFunding**. Information about the financiers.
     *
     * @return self
     */
    public function setFinanciers($financiers)
    {
        $this->container['financiers'] = $financiers;

        return $this;
    }

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

    /**
     * Sets originatorLegalEntityId
     *
     * @param string|null $originatorLegalEntityId Required if `type` is **donations** or **inheritance**. The legal entity ID representing the originator of the source of funds.  For example, if the source of funds is **inheritance**, then `originatorOfFundsReference` should be the legal entity reference of the benefactor.
     *
     * @return self
     */
    public function setOriginatorLegalEntityId($originatorLegalEntityId)
    {
        $this->container['originatorLegalEntityId'] = $originatorLegalEntityId;

        return $this;
    }

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

    /**
     * Sets purpose
     *
     * @param string|null $purpose Required if `type` is **donations**. The reason for receiving the funds.
     *
     * @return self
     */
    public function setPurpose($purpose)
    {
        $this->container['purpose'] = $purpose;

        return $this;
    }

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

    /**
     * Sets relationship
     *
     * @param string|null $relationship Required if `type` is **donations** or **inheritance**. The relationship of the originator of the funds to the recipient.
     *
     * @return self
     */
    public function setRelationship($relationship)
    {
        $this->container['relationship'] = $relationship;

        return $this;
    }

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

    /**
     * Sets type
     *
     * @param string|null $type The type of the source of funds.    Possible values: *  **business** *  **employment** *  **donations** *  **inheritance** *  **financialAid** *  **rentalIncome** *  **dividendIncome** *  **royaltyIncome** *  **thirdPartyFunding** *  **pensionIncome** *  **insuranceSettlement** *  **cryptocurrencyIncome** *  **assetSale** *  **loans** *  **gamblingWinnings**
     *
     * @return self
     */
    public function setType($type)
    {
        $allowedValues = $this->getTypeAllowableValues();
        if (!in_array($type, $allowedValues, true)) {
            error_log(
                sprintf(
                    "type: unexpected enum value '%s' - Supported values are [%s]",
                    $type,
                    implode(', ', $allowedValues)
                )
            );
        }
        $this->container['type'] = $type;

        return $this;
    }

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

    /**
     * Sets website
     *
     * @param string|null $website Required if `type` is **gamblingWinnings**. The location of the gambling site for the winnings.  For example, if the source of funds is online gambling, provide the website of the gambling company.
     *
     * @return self
     */
    public function setWebsite($website)
    {
        $this->container['website'] = $website;

        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|null
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($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 $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.
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize()
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    public function toArray(): array
    {
        $array = [];
        foreach (self::$openAPITypes as $propertyName => $propertyType) {
            $propertyValue = $this[$propertyName];
            if ($propertyValue !== null) {
                // Check if the property value is an object and has a toArray() method
                if (is_object($propertyValue) && method_exists($propertyValue, 'toArray')) {
                    $array[$propertyName] = $propertyValue->toArray();
                // Check if it's type datetime
                } elseif ($propertyValue instanceof \DateTime) {
                    $array[$propertyName] = $propertyValue->format(DATE_ATOM);
                // If it's an array type we should check whether it contains objects and if so call toArray method
                } elseif (is_array($propertyValue)) {
                    $array[$propertyName] = array_map(function ($item) {
                        return $item instanceof ModelInterface ? $item->toArray() : $item;
                    }, $propertyValue);
                } else {
                    // Otherwise, directly assign the property value to the array
                    $array[$propertyName] = $propertyValue;
                }
            }
        }
        return $array;
    }

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