<?php
/**
 * Credential
 *
 * PHP version 7.4
 *
 * @category Class
 * @package  Corbado\Generated
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * Corbado Backend API
 *
 * # Introduction This documentation gives an overview of all Corbado Backend API calls to implement passwordless authentication with Passkeys.
 *
 * The version of the OpenAPI document: 2.0.0
 * Contact: support@corbado.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0-SNAPSHOT
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Corbado\Generated\Model;

use \ArrayAccess;
use \Corbado\Generated\ObjectSerializer;

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

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

    /**
      * Array of property to type mappings. Used for (de)serialization
      *
      * @var string[]
      */
    protected static $openAPITypes = [
        'id' => 'string',
        'credential_id' => 'string',
        'attestation_type' => 'string',
        'transport' => 'string[]',
        'backup_eligible' => 'bool',
        'backup_state' => 'bool',
        'authenticator_aaguid' => 'string',
        'source_os' => 'string',
        'source_browser' => 'string',
        'last_used' => 'string',
        'created' => 'string',
        'status' => '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 = [
        'id' => null,
        'credential_id' => null,
        'attestation_type' => null,
        'transport' => null,
        'backup_eligible' => null,
        'backup_state' => null,
        'authenticator_aaguid' => null,
        'source_os' => null,
        'source_browser' => null,
        'last_used' => null,
        'created' => null,
        'status' => null
    ];

    /**
      * Array of nullable properties. Used for (de)serialization
      *
      * @var boolean[]
      */
    protected static array $openAPINullables = [
        'id' => false,
        'credential_id' => false,
        'attestation_type' => false,
        'transport' => false,
        'backup_eligible' => false,
        'backup_state' => false,
        'authenticator_aaguid' => false,
        'source_os' => false,
        'source_browser' => false,
        'last_used' => false,
        'created' => false,
        'status' => 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 = [
        'id' => 'id',
        'credential_id' => 'credentialID',
        'attestation_type' => 'attestationType',
        'transport' => 'transport',
        'backup_eligible' => 'backupEligible',
        'backup_state' => 'backupState',
        'authenticator_aaguid' => 'authenticatorAAGUID',
        'source_os' => 'sourceOS',
        'source_browser' => 'sourceBrowser',
        'last_used' => 'lastUsed',
        'created' => 'created',
        'status' => 'status'
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses)
     *
     * @var string[]
     */
    protected static $setters = [
        'id' => 'setId',
        'credential_id' => 'setCredentialId',
        'attestation_type' => 'setAttestationType',
        'transport' => 'setTransport',
        'backup_eligible' => 'setBackupEligible',
        'backup_state' => 'setBackupState',
        'authenticator_aaguid' => 'setAuthenticatorAaguid',
        'source_os' => 'setSourceOs',
        'source_browser' => 'setSourceBrowser',
        'last_used' => 'setLastUsed',
        'created' => 'setCreated',
        'status' => 'setStatus'
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests)
     *
     * @var string[]
     */
    protected static $getters = [
        'id' => 'getId',
        'credential_id' => 'getCredentialId',
        'attestation_type' => 'getAttestationType',
        'transport' => 'getTransport',
        'backup_eligible' => 'getBackupEligible',
        'backup_state' => 'getBackupState',
        'authenticator_aaguid' => 'getAuthenticatorAaguid',
        'source_os' => 'getSourceOs',
        'source_browser' => 'getSourceBrowser',
        'last_used' => 'getLastUsed',
        'created' => 'getCreated',
        'status' => 'getStatus'
    ];

    /**
     * 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 TRANSPORT_USB = 'usb';
    public const TRANSPORT_NFC = 'nfc';
    public const TRANSPORT_BLE = 'ble';
    public const TRANSPORT_INTERNAL = 'internal';
    public const TRANSPORT_HYBRID = 'hybrid';
    public const TRANSPORT_SMART_CARD = 'smart-card';
    public const STATUS_PENDING = 'pending';
    public const STATUS_ACTIVE = 'active';

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getTransportAllowableValues()
    {
        return [
            self::TRANSPORT_USB,
            self::TRANSPORT_NFC,
            self::TRANSPORT_BLE,
            self::TRANSPORT_INTERNAL,
            self::TRANSPORT_HYBRID,
            self::TRANSPORT_SMART_CARD,
        ];
    }

    /**
     * Gets allowable values of the enum
     *
     * @return string[]
     */
    public function getStatusAllowableValues()
    {
        return [
            self::STATUS_PENDING,
            self::STATUS_ACTIVE,
        ];
    }

    /**
     * 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('id', $data ?? [], null);
        $this->setIfExists('credential_id', $data ?? [], null);
        $this->setIfExists('attestation_type', $data ?? [], null);
        $this->setIfExists('transport', $data ?? [], null);
        $this->setIfExists('backup_eligible', $data ?? [], null);
        $this->setIfExists('backup_state', $data ?? [], null);
        $this->setIfExists('authenticator_aaguid', $data ?? [], null);
        $this->setIfExists('source_os', $data ?? [], null);
        $this->setIfExists('source_browser', $data ?? [], null);
        $this->setIfExists('last_used', $data ?? [], null);
        $this->setIfExists('created', $data ?? [], null);
        $this->setIfExists('status', $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['id'] === null) {
            $invalidProperties[] = "'id' can't be null";
        }
        if ($this->container['credential_id'] === null) {
            $invalidProperties[] = "'credential_id' can't be null";
        }
        if ($this->container['attestation_type'] === null) {
            $invalidProperties[] = "'attestation_type' can't be null";
        }
        if ($this->container['transport'] === null) {
            $invalidProperties[] = "'transport' can't be null";
        }
        if ($this->container['backup_eligible'] === null) {
            $invalidProperties[] = "'backup_eligible' can't be null";
        }
        if ($this->container['backup_state'] === null) {
            $invalidProperties[] = "'backup_state' can't be null";
        }
        if ($this->container['authenticator_aaguid'] === null) {
            $invalidProperties[] = "'authenticator_aaguid' can't be null";
        }
        if ($this->container['source_os'] === null) {
            $invalidProperties[] = "'source_os' can't be null";
        }
        if ($this->container['source_browser'] === null) {
            $invalidProperties[] = "'source_browser' can't be null";
        }
        if ($this->container['last_used'] === null) {
            $invalidProperties[] = "'last_used' can't be null";
        }
        if ($this->container['created'] === null) {
            $invalidProperties[] = "'created' can't be null";
        }
        if ($this->container['status'] === null) {
            $invalidProperties[] = "'status' can't be null";
        }
        $allowedValues = $this->getStatusAllowableValues();
        if (!is_null($this->container['status']) && !in_array($this->container['status'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'status', must be one of '%s'",
                $this->container['status'],
                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 id
     *
     * @return string
     */
    public function getId()
    {
        return $this->container['id'];
    }

    /**
     * Sets id
     *
     * @param string $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 credential_id
     *
     * @return string
     */
    public function getCredentialId()
    {
        return $this->container['credential_id'];
    }

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

        return $this;
    }

    /**
     * Gets attestation_type
     *
     * @return string
     */
    public function getAttestationType()
    {
        return $this->container['attestation_type'];
    }

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

        return $this;
    }

    /**
     * Gets transport
     *
     * @return string[]
     */
    public function getTransport()
    {
        return $this->container['transport'];
    }

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

        return $this;
    }

    /**
     * Gets backup_eligible
     *
     * @return bool
     */
    public function getBackupEligible()
    {
        return $this->container['backup_eligible'];
    }

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

        return $this;
    }

    /**
     * Gets backup_state
     *
     * @return bool
     */
    public function getBackupState()
    {
        return $this->container['backup_state'];
    }

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

        return $this;
    }

    /**
     * Gets authenticator_aaguid
     *
     * @return string
     */
    public function getAuthenticatorAaguid()
    {
        return $this->container['authenticator_aaguid'];
    }

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

        return $this;
    }

    /**
     * Gets source_os
     *
     * @return string
     */
    public function getSourceOs()
    {
        return $this->container['source_os'];
    }

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

        return $this;
    }

    /**
     * Gets source_browser
     *
     * @return string
     */
    public function getSourceBrowser()
    {
        return $this->container['source_browser'];
    }

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

        return $this;
    }

    /**
     * Gets last_used
     *
     * @return string
     */
    public function getLastUsed()
    {
        return $this->container['last_used'];
    }

    /**
     * Sets last_used
     *
     * @param string $last_used Timestamp of when the passkey was last used in yyyy-MM-dd'T'HH:mm:ss format
     *
     * @return self
     */
    public function setLastUsed($last_used)
    {
        if (is_null($last_used)) {
            throw new \InvalidArgumentException('non-nullable last_used cannot be null');
        }
        $this->container['last_used'] = $last_used;

        return $this;
    }

    /**
     * Gets created
     *
     * @return string
     */
    public function getCreated()
    {
        return $this->container['created'];
    }

    /**
     * Sets created
     *
     * @param string $created Timestamp of when the entity was created in yyyy-MM-dd'T'HH:mm:ss format
     *
     * @return self
     */
    public function setCreated($created)
    {
        if (is_null($created)) {
            throw new \InvalidArgumentException('non-nullable created cannot be null');
        }
        $this->container['created'] = $created;

        return $this;
    }

    /**
     * Gets status
     *
     * @return string
     */
    public function getStatus()
    {
        return $this->container['status'];
    }

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

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

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


