<?php

/**
 * Management API
 *
 * The version of the OpenAPI document: 3
 * 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\Management;

use \ArrayAccess;
use Adyen\Model\Management\ObjectSerializer;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'links' => '\Adyen\Model\Management\PaginationLinks',
        'data' => '\Adyen\Model\Management\PaymentMethod[]',
        'itemsTotal' => 'int',
        'pagesTotal' => 'int',
        'typesWithErrors' => '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 = [
        'links' => null,
        'data' => null,
        'itemsTotal' => 'int32',
        'pagesTotal' => 'int32',
        'typesWithErrors' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static $openAPINullables = [
        'links' => false,
        'data' => false,
        'itemsTotal' => true,
        'pagesTotal' => true,
        'typesWithErrors' => 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 = [
        'links' => '_links',
        'data' => 'data',
        'itemsTotal' => 'itemsTotal',
        'pagesTotal' => 'pagesTotal',
        'typesWithErrors' => 'typesWithErrors'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'links' => 'setLinks',
        'data' => 'setData',
        'itemsTotal' => 'setItemsTotal',
        'pagesTotal' => 'setPagesTotal',
        'typesWithErrors' => 'setTypesWithErrors'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'links' => 'getLinks',
        'data' => 'getData',
        'itemsTotal' => 'getItemsTotal',
        'pagesTotal' => 'getPagesTotal',
        'typesWithErrors' => 'getTypesWithErrors'
    ];

    /**
     * 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 TYPES_WITH_ERRORS_ACCEL = 'accel';
    public const TYPES_WITH_ERRORS_ACH = 'ach';
    public const TYPES_WITH_ERRORS_AFFIRM = 'affirm';
    public const TYPES_WITH_ERRORS_AFTERPAYTOUCH = 'afterpaytouch';
    public const TYPES_WITH_ERRORS_ALELO = 'alelo';
    public const TYPES_WITH_ERRORS_ALIPAY = 'alipay';
    public const TYPES_WITH_ERRORS_ALIPAY_HK = 'alipay_hk';
    public const TYPES_WITH_ERRORS_ALIPAY_WAP = 'alipay_wap';
    public const TYPES_WITH_ERRORS_AMEX = 'amex';
    public const TYPES_WITH_ERRORS_APPLEPAY = 'applepay';
    public const TYPES_WITH_ERRORS_BANESE_CARD = 'banese_card';
    public const TYPES_WITH_ERRORS_BANESE_CARD_CREDIT = 'banese_card_credit';
    public const TYPES_WITH_ERRORS_BANESE_CARD_DEBIT = 'banese_card_debit';
    public const TYPES_WITH_ERRORS_BANESE_CARD_PREPAID = 'banese_card_prepaid';
    public const TYPES_WITH_ERRORS_BCMC = 'bcmc';
    public const TYPES_WITH_ERRORS_BLIK = 'blik';
    public const TYPES_WITH_ERRORS_CARTEBANCAIRE = 'cartebancaire';
    public const TYPES_WITH_ERRORS_CLEARPAY = 'clearpay';
    public const TYPES_WITH_ERRORS_CLICKTOPAY = 'clicktopay';
    public const TYPES_WITH_ERRORS_CREDTODOS = 'credtodos';
    public const TYPES_WITH_ERRORS_CREDTODOS_PRIVATE_CREDIT = 'credtodos_private_credit';
    public const TYPES_WITH_ERRORS_CREDTODOS_PRIVATE_DEBIT = 'credtodos_private_debit';
    public const TYPES_WITH_ERRORS_CUP = 'cup';
    public const TYPES_WITH_ERRORS_DINERS = 'diners';
    public const TYPES_WITH_ERRORS_DIRECTDEBIT_GB = 'directdebit_GB';
    public const TYPES_WITH_ERRORS_DISCOVER = 'discover';
    public const TYPES_WITH_ERRORS_EBANKING_FI = 'ebanking_FI';
    public const TYPES_WITH_ERRORS_EFT_DIRECTDEBIT_CA = 'eft_directdebit_CA';
    public const TYPES_WITH_ERRORS_EFTPOS_AUSTRALIA = 'eftpos_australia';
    public const TYPES_WITH_ERRORS_ELO = 'elo';
    public const TYPES_WITH_ERRORS_ELOCREDIT = 'elocredit';
    public const TYPES_WITH_ERRORS_ELODEBIT = 'elodebit';
    public const TYPES_WITH_ERRORS_GIROCARD = 'girocard';
    public const TYPES_WITH_ERRORS_GOOGLEPAY = 'googlepay';
    public const TYPES_WITH_ERRORS_HIPER = 'hiper';
    public const TYPES_WITH_ERRORS_HIPERCARD = 'hipercard';
    public const TYPES_WITH_ERRORS_IDEAL = 'ideal';
    public const TYPES_WITH_ERRORS_INTERAC_CARD = 'interac_card';
    public const TYPES_WITH_ERRORS_JCB = 'jcb';
    public const TYPES_WITH_ERRORS_KLARNA = 'klarna';
    public const TYPES_WITH_ERRORS_KLARNA_ACCOUNT = 'klarna_account';
    public const TYPES_WITH_ERRORS_KLARNA_PAYNOW = 'klarna_paynow';
    public const TYPES_WITH_ERRORS_MAESTRO = 'maestro';
    public const TYPES_WITH_ERRORS_MBWAY = 'mbway';
    public const TYPES_WITH_ERRORS_MC = 'mc';
    public const TYPES_WITH_ERRORS_MCDEBIT = 'mcdebit';
    public const TYPES_WITH_ERRORS_MEAL_VOUCHER_FR = 'mealVoucher_FR';
    public const TYPES_WITH_ERRORS_MOBILEPAY = 'mobilepay';
    public const TYPES_WITH_ERRORS_MULTIBANCO = 'multibanco';
    public const TYPES_WITH_ERRORS_NYCE = 'nyce';
    public const TYPES_WITH_ERRORS_ONLINE_BANKING_PL = 'onlineBanking_PL';
    public const TYPES_WITH_ERRORS_PAYBYBANK = 'paybybank';
    public const TYPES_WITH_ERRORS_PAYME = 'payme';
    public const TYPES_WITH_ERRORS_PAYME_POS = 'payme_pos';
    public const TYPES_WITH_ERRORS_PAYNOW = 'paynow';
    public const TYPES_WITH_ERRORS_PAYNOW_POS = 'paynow_pos';
    public const TYPES_WITH_ERRORS_PAYPAL = 'paypal';
    public const TYPES_WITH_ERRORS_PAYSHOP = 'payshop';
    public const TYPES_WITH_ERRORS_PAYTO = 'payto';
    public const TYPES_WITH_ERRORS_PULSE = 'pulse';
    public const TYPES_WITH_ERRORS_SODEXO = 'sodexo';
    public const TYPES_WITH_ERRORS_STAR = 'star';
    public const TYPES_WITH_ERRORS_SWISH = 'swish';
    public const TYPES_WITH_ERRORS_TICKET = 'ticket';
    public const TYPES_WITH_ERRORS_TODO_GIFTCARD = 'todo_giftcard';
    public const TYPES_WITH_ERRORS_TRUSTLY = 'trustly';
    public const TYPES_WITH_ERRORS_TWINT = 'twint';
    public const TYPES_WITH_ERRORS_TWINT_POS = 'twint_pos';
    public const TYPES_WITH_ERRORS_UP_BRAZIL_CREDIT = 'up_brazil_credit';
    public const TYPES_WITH_ERRORS_VALE_REFEICAO = 'vale_refeicao';
    public const TYPES_WITH_ERRORS_VALE_REFEICAO_PREPAID = 'vale_refeicao_prepaid';
    public const TYPES_WITH_ERRORS_VIPPS = 'vipps';
    public const TYPES_WITH_ERRORS_VISA = 'visa';
    public const TYPES_WITH_ERRORS_VISADEBIT = 'visadebit';
    public const TYPES_WITH_ERRORS_VPAY = 'vpay';
    public const TYPES_WITH_ERRORS_WECHATPAY = 'wechatpay';
    public const TYPES_WITH_ERRORS_WECHATPAY_POS = 'wechatpay_pos';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getTypesWithErrorsAllowableValues()
    {
        return [
            self::TYPES_WITH_ERRORS_ACCEL,
            self::TYPES_WITH_ERRORS_ACH,
            self::TYPES_WITH_ERRORS_AFFIRM,
            self::TYPES_WITH_ERRORS_AFTERPAYTOUCH,
            self::TYPES_WITH_ERRORS_ALELO,
            self::TYPES_WITH_ERRORS_ALIPAY,
            self::TYPES_WITH_ERRORS_ALIPAY_HK,
            self::TYPES_WITH_ERRORS_ALIPAY_WAP,
            self::TYPES_WITH_ERRORS_AMEX,
            self::TYPES_WITH_ERRORS_APPLEPAY,
            self::TYPES_WITH_ERRORS_BANESE_CARD,
            self::TYPES_WITH_ERRORS_BANESE_CARD_CREDIT,
            self::TYPES_WITH_ERRORS_BANESE_CARD_DEBIT,
            self::TYPES_WITH_ERRORS_BANESE_CARD_PREPAID,
            self::TYPES_WITH_ERRORS_BCMC,
            self::TYPES_WITH_ERRORS_BLIK,
            self::TYPES_WITH_ERRORS_CARTEBANCAIRE,
            self::TYPES_WITH_ERRORS_CLEARPAY,
            self::TYPES_WITH_ERRORS_CLICKTOPAY,
            self::TYPES_WITH_ERRORS_CREDTODOS,
            self::TYPES_WITH_ERRORS_CREDTODOS_PRIVATE_CREDIT,
            self::TYPES_WITH_ERRORS_CREDTODOS_PRIVATE_DEBIT,
            self::TYPES_WITH_ERRORS_CUP,
            self::TYPES_WITH_ERRORS_DINERS,
            self::TYPES_WITH_ERRORS_DIRECTDEBIT_GB,
            self::TYPES_WITH_ERRORS_DISCOVER,
            self::TYPES_WITH_ERRORS_EBANKING_FI,
            self::TYPES_WITH_ERRORS_EFT_DIRECTDEBIT_CA,
            self::TYPES_WITH_ERRORS_EFTPOS_AUSTRALIA,
            self::TYPES_WITH_ERRORS_ELO,
            self::TYPES_WITH_ERRORS_ELOCREDIT,
            self::TYPES_WITH_ERRORS_ELODEBIT,
            self::TYPES_WITH_ERRORS_GIROCARD,
            self::TYPES_WITH_ERRORS_GOOGLEPAY,
            self::TYPES_WITH_ERRORS_HIPER,
            self::TYPES_WITH_ERRORS_HIPERCARD,
            self::TYPES_WITH_ERRORS_IDEAL,
            self::TYPES_WITH_ERRORS_INTERAC_CARD,
            self::TYPES_WITH_ERRORS_JCB,
            self::TYPES_WITH_ERRORS_KLARNA,
            self::TYPES_WITH_ERRORS_KLARNA_ACCOUNT,
            self::TYPES_WITH_ERRORS_KLARNA_PAYNOW,
            self::TYPES_WITH_ERRORS_MAESTRO,
            self::TYPES_WITH_ERRORS_MBWAY,
            self::TYPES_WITH_ERRORS_MC,
            self::TYPES_WITH_ERRORS_MCDEBIT,
            self::TYPES_WITH_ERRORS_MEAL_VOUCHER_FR,
            self::TYPES_WITH_ERRORS_MOBILEPAY,
            self::TYPES_WITH_ERRORS_MULTIBANCO,
            self::TYPES_WITH_ERRORS_NYCE,
            self::TYPES_WITH_ERRORS_ONLINE_BANKING_PL,
            self::TYPES_WITH_ERRORS_PAYBYBANK,
            self::TYPES_WITH_ERRORS_PAYME,
            self::TYPES_WITH_ERRORS_PAYME_POS,
            self::TYPES_WITH_ERRORS_PAYNOW,
            self::TYPES_WITH_ERRORS_PAYNOW_POS,
            self::TYPES_WITH_ERRORS_PAYPAL,
            self::TYPES_WITH_ERRORS_PAYSHOP,
            self::TYPES_WITH_ERRORS_PAYTO,
            self::TYPES_WITH_ERRORS_PULSE,
            self::TYPES_WITH_ERRORS_SODEXO,
            self::TYPES_WITH_ERRORS_STAR,
            self::TYPES_WITH_ERRORS_SWISH,
            self::TYPES_WITH_ERRORS_TICKET,
            self::TYPES_WITH_ERRORS_TODO_GIFTCARD,
            self::TYPES_WITH_ERRORS_TRUSTLY,
            self::TYPES_WITH_ERRORS_TWINT,
            self::TYPES_WITH_ERRORS_TWINT_POS,
            self::TYPES_WITH_ERRORS_UP_BRAZIL_CREDIT,
            self::TYPES_WITH_ERRORS_VALE_REFEICAO,
            self::TYPES_WITH_ERRORS_VALE_REFEICAO_PREPAID,
            self::TYPES_WITH_ERRORS_VIPPS,
            self::TYPES_WITH_ERRORS_VISA,
            self::TYPES_WITH_ERRORS_VISADEBIT,
            self::TYPES_WITH_ERRORS_VPAY,
            self::TYPES_WITH_ERRORS_WECHATPAY,
            self::TYPES_WITH_ERRORS_WECHATPAY_POS,
        ];
    }
    /**
     * 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('links', $data ?? [], null);
        $this->setIfExists('data', $data ?? [], null);
        $this->setIfExists('itemsTotal', $data ?? [], null);
        $this->setIfExists('pagesTotal', $data ?? [], null);
        $this->setIfExists('typesWithErrors', $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['itemsTotal'] === null) {
            $invalidProperties[] = "'itemsTotal' can't be null";
        }
        if ($this->container['pagesTotal'] === null) {
            $invalidProperties[] = "'pagesTotal' 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 links
     *
     * @return \Adyen\Model\Management\PaginationLinks|null
     */
    public function getLinks()
    {
        return $this->container['links'];
    }

    /**
     * Sets links
     *
     * @param \Adyen\Model\Management\PaginationLinks|null $links links
     *
     * @return self
     */
    public function setLinks($links)
    {
        $this->container['links'] = $links;

        return $this;
    }

    /**
     * Gets data
     *
     * @return \Adyen\Model\Management\PaymentMethod[]|null
     */
    public function getData()
    {
        return $this->container['data'];
    }

    /**
     * Sets data
     *
     * @param \Adyen\Model\Management\PaymentMethod[]|null $data The list of supported payment methods and their details.
     *
     * @return self
     */
    public function setData($data)
    {
        $this->container['data'] = $data;

        return $this;
    }

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

    /**
     * Sets itemsTotal
     *
     * @param int $itemsTotal Total number of items.
     *
     * @return self
     */
    public function setItemsTotal($itemsTotal)
    {
        $this->container['itemsTotal'] = $itemsTotal;

        return $this;
    }

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

    /**
     * Sets pagesTotal
     *
     * @param int $pagesTotal Total number of pages.
     *
     * @return self
     */
    public function setPagesTotal($pagesTotal)
    {
        $this->container['pagesTotal'] = $pagesTotal;

        return $this;
    }

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

    /**
     * Sets typesWithErrors
     *
     * @param string[]|null $typesWithErrors Payment method types with errors.
     *
     * @return self
     */
    public function setTypesWithErrors($typesWithErrors)
    {
        $allowedValues = $this->getTypesWithErrorsAllowableValues();
        if (array_diff($typesWithErrors, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'typesWithErrors', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['typesWithErrors'] = $typesWithErrors;

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