<?php
/**
 * WalletApi
 * PHP version 5
 *
 * @category Class
 * @package  com\hydrogen\molecule
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * Molecule API Documentation
 *
 * The Hydrogen Molecule API
 *
 * OpenAPI spec version: 1.3.0
 * Contact: info@hydrogenplatform.com
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 * Swagger Codegen version: 2.4.14
 */

/**
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen
 * Do not edit the class manually.
 */

namespace com\hydrogen\molecule\Api;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\RequestOptions;
use com\hydrogen\molecule\ApiException;
use com\hydrogen\molecule\Configuration;
use com\hydrogen\molecule\HeaderSelector;
use com\hydrogen\molecule\ObjectSerializer;

/**
 * WalletApi Class Doc Comment
 *
 * @category Class
 * @package  com\hydrogen\molecule
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class WalletApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var Configuration
     */
    protected $config;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     */
    public function __construct(
        ClientInterface $client = null,
        Configuration $config = null,
        HeaderSelector $selector = null
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: new Configuration();
        $this->headerSelector = $selector ?: new HeaderSelector();
    }

    /**
     * @return Configuration
     */
    public function getConfig()
    {
        return $this->config;
    }

    /**
     * Operation createWalletUsingPost
     *
     * Creates a new Wallet
     *
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_params It enables a user to create a Wallet (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \com\hydrogen\molecule\Model\WalletResponse
     */
    public function createWalletUsingPost($wallet_params)
    {
        list($response) = $this->createWalletUsingPostWithHttpInfo($wallet_params);
        return $response;
    }

    /**
     * Operation createWalletUsingPostWithHttpInfo
     *
     * Creates a new Wallet
     *
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_params It enables a user to create a Wallet (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \com\hydrogen\molecule\Model\WalletResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function createWalletUsingPostWithHttpInfo($wallet_params)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->createWalletUsingPostRequest($wallet_params);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\WalletResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation createWalletUsingPostAsync
     *
     * Creates a new Wallet
     *
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_params It enables a user to create a Wallet (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createWalletUsingPostAsync($wallet_params)
    {
        return $this->createWalletUsingPostAsyncWithHttpInfo($wallet_params)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation createWalletUsingPostAsyncWithHttpInfo
     *
     * Creates a new Wallet
     *
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_params It enables a user to create a Wallet (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function createWalletUsingPostAsyncWithHttpInfo($wallet_params)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->createWalletUsingPostRequest($wallet_params);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'createWalletUsingPost'
     *
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_params It enables a user to create a Wallet (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function createWalletUsingPostRequest($wallet_params)
    {
        // verify the required parameter 'wallet_params' is set
        if ($wallet_params === null || (is_array($wallet_params) && count($wallet_params) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $wallet_params when calling createWalletUsingPost'
            );
        }

        $resourcePath = '/wallet';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



        // body params
        $_tempBody = null;
        if (isset($wallet_params)) {
            $_tempBody = $wallet_params;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            
            if($headers['Content-Type'] === 'application/json') {
                // \stdClass has no __toString(), so we should encode it manually
                if ($httpBody instanceof \stdClass) {
                    $httpBody = \GuzzleHttp\json_encode($httpBody);
                }
                // array has no __toString(), so we should encode it manually
                if(is_array($httpBody)) {
                    $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
                }
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'POST',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getWalletAllUsingGet
     *
     * Fetch Wallet list
     *
     * @param  string $nucleus_client_id To filter response wallet list by client&#39;s ID (optional)
     * @param  bool $is_primary To filter response for primary wallets (optional)
     * @param  int $page To filter response wallet list by page number (optional)
     * @param  int $size Number of records per page (optional)
     * @param  string $order_by Field to sort record list (optional)
     * @param  bool $ascending Sorting order (optional)
     * @param  bool $get_latest To fetch latest (one) record (optional)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \com\hydrogen\molecule\Model\PageWalletResponse_
     */
    public function getWalletAllUsingGet($nucleus_client_id = null, $is_primary = null, $page = null, $size = null, $order_by = null, $ascending = null, $get_latest = null)
    {
        list($response) = $this->getWalletAllUsingGetWithHttpInfo($nucleus_client_id, $is_primary, $page, $size, $order_by, $ascending, $get_latest);
        return $response;
    }

    /**
     * Operation getWalletAllUsingGetWithHttpInfo
     *
     * Fetch Wallet list
     *
     * @param  string $nucleus_client_id To filter response wallet list by client&#39;s ID (optional)
     * @param  bool $is_primary To filter response for primary wallets (optional)
     * @param  int $page To filter response wallet list by page number (optional)
     * @param  int $size Number of records per page (optional)
     * @param  string $order_by Field to sort record list (optional)
     * @param  bool $ascending Sorting order (optional)
     * @param  bool $get_latest To fetch latest (one) record (optional)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \com\hydrogen\molecule\Model\PageWalletResponse_, HTTP status code, HTTP response headers (array of strings)
     */
    public function getWalletAllUsingGetWithHttpInfo($nucleus_client_id = null, $is_primary = null, $page = null, $size = null, $order_by = null, $ascending = null, $get_latest = null)
    {
        $returnType = '\com\hydrogen\molecule\Model\PageWalletResponse_';
        $request = $this->getWalletAllUsingGetRequest($nucleus_client_id, $is_primary, $page, $size, $order_by, $ascending, $get_latest);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\PageWalletResponse_',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getWalletAllUsingGetAsync
     *
     * Fetch Wallet list
     *
     * @param  string $nucleus_client_id To filter response wallet list by client&#39;s ID (optional)
     * @param  bool $is_primary To filter response for primary wallets (optional)
     * @param  int $page To filter response wallet list by page number (optional)
     * @param  int $size Number of records per page (optional)
     * @param  string $order_by Field to sort record list (optional)
     * @param  bool $ascending Sorting order (optional)
     * @param  bool $get_latest To fetch latest (one) record (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletAllUsingGetAsync($nucleus_client_id = null, $is_primary = null, $page = null, $size = null, $order_by = null, $ascending = null, $get_latest = null)
    {
        return $this->getWalletAllUsingGetAsyncWithHttpInfo($nucleus_client_id, $is_primary, $page, $size, $order_by, $ascending, $get_latest)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getWalletAllUsingGetAsyncWithHttpInfo
     *
     * Fetch Wallet list
     *
     * @param  string $nucleus_client_id To filter response wallet list by client&#39;s ID (optional)
     * @param  bool $is_primary To filter response for primary wallets (optional)
     * @param  int $page To filter response wallet list by page number (optional)
     * @param  int $size Number of records per page (optional)
     * @param  string $order_by Field to sort record list (optional)
     * @param  bool $ascending Sorting order (optional)
     * @param  bool $get_latest To fetch latest (one) record (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletAllUsingGetAsyncWithHttpInfo($nucleus_client_id = null, $is_primary = null, $page = null, $size = null, $order_by = null, $ascending = null, $get_latest = null)
    {
        $returnType = '\com\hydrogen\molecule\Model\PageWalletResponse_';
        $request = $this->getWalletAllUsingGetRequest($nucleus_client_id, $is_primary, $page, $size, $order_by, $ascending, $get_latest);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getWalletAllUsingGet'
     *
     * @param  string $nucleus_client_id To filter response wallet list by client&#39;s ID (optional)
     * @param  bool $is_primary To filter response for primary wallets (optional)
     * @param  int $page To filter response wallet list by page number (optional)
     * @param  int $size Number of records per page (optional)
     * @param  string $order_by Field to sort record list (optional)
     * @param  bool $ascending Sorting order (optional)
     * @param  bool $get_latest To fetch latest (one) record (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getWalletAllUsingGetRequest($nucleus_client_id = null, $is_primary = null, $page = null, $size = null, $order_by = null, $ascending = null, $get_latest = null)
    {

        $resourcePath = '/wallet';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        if ($nucleus_client_id !== null) {
            $queryParams['nucleus_client_id'] = ObjectSerializer::toQueryValue($nucleus_client_id);
        }
        // query params
        if ($is_primary !== null) {
            $queryParams['is_primary'] = ObjectSerializer::toQueryValue($is_primary);
        }
        // query params
        if ($page !== null) {
            $queryParams['page'] = ObjectSerializer::toQueryValue($page);
        }
        // query params
        if ($size !== null) {
            $queryParams['size'] = ObjectSerializer::toQueryValue($size);
        }
        // query params
        if ($order_by !== null) {
            $queryParams['order_by'] = ObjectSerializer::toQueryValue($order_by);
        }
        // query params
        if ($ascending !== null) {
            $queryParams['ascending'] = ObjectSerializer::toQueryValue($ascending);
        }
        // query params
        if ($get_latest !== null) {
            $queryParams['get_latest'] = ObjectSerializer::toQueryValue($get_latest);
        }


        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            
            if($headers['Content-Type'] === 'application/json') {
                // \stdClass has no __toString(), so we should encode it manually
                if ($httpBody instanceof \stdClass) {
                    $httpBody = \GuzzleHttp\json_encode($httpBody);
                }
                // array has no __toString(), so we should encode it manually
                if(is_array($httpBody)) {
                    $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
                }
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getWalletByWalletKeyUsingGet
     *
     * Fetch Wallet details by Wallet Key ID
     *
     * @param  string $wallet_key_id Wallet Key ID (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \com\hydrogen\molecule\Model\WalletResponse
     */
    public function getWalletByWalletKeyUsingGet($wallet_key_id)
    {
        list($response) = $this->getWalletByWalletKeyUsingGetWithHttpInfo($wallet_key_id);
        return $response;
    }

    /**
     * Operation getWalletByWalletKeyUsingGetWithHttpInfo
     *
     * Fetch Wallet details by Wallet Key ID
     *
     * @param  string $wallet_key_id Wallet Key ID (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \com\hydrogen\molecule\Model\WalletResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getWalletByWalletKeyUsingGetWithHttpInfo($wallet_key_id)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->getWalletByWalletKeyUsingGetRequest($wallet_key_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\WalletResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getWalletByWalletKeyUsingGetAsync
     *
     * Fetch Wallet details by Wallet Key ID
     *
     * @param  string $wallet_key_id Wallet Key ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletByWalletKeyUsingGetAsync($wallet_key_id)
    {
        return $this->getWalletByWalletKeyUsingGetAsyncWithHttpInfo($wallet_key_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getWalletByWalletKeyUsingGetAsyncWithHttpInfo
     *
     * Fetch Wallet details by Wallet Key ID
     *
     * @param  string $wallet_key_id Wallet Key ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletByWalletKeyUsingGetAsyncWithHttpInfo($wallet_key_id)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->getWalletByWalletKeyUsingGetRequest($wallet_key_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getWalletByWalletKeyUsingGet'
     *
     * @param  string $wallet_key_id Wallet Key ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getWalletByWalletKeyUsingGetRequest($wallet_key_id)
    {
        // verify the required parameter 'wallet_key_id' is set
        if ($wallet_key_id === null || (is_array($wallet_key_id) && count($wallet_key_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $wallet_key_id when calling getWalletByWalletKeyUsingGet'
            );
        }

        $resourcePath = '/wallet/wallet_key/{wallet_key_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($wallet_key_id !== null) {
            $resourcePath = str_replace(
                '{' . 'wallet_key_id' . '}',
                ObjectSerializer::toPathValue($wallet_key_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            
            if($headers['Content-Type'] === 'application/json') {
                // \stdClass has no __toString(), so we should encode it manually
                if ($httpBody instanceof \stdClass) {
                    $httpBody = \GuzzleHttp\json_encode($httpBody);
                }
                // array has no __toString(), so we should encode it manually
                if(is_array($httpBody)) {
                    $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
                }
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getWalletUsingGet
     *
     * Fetch Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \com\hydrogen\molecule\Model\WalletResponse
     */
    public function getWalletUsingGet($wallet_id)
    {
        list($response) = $this->getWalletUsingGetWithHttpInfo($wallet_id);
        return $response;
    }

    /**
     * Operation getWalletUsingGetWithHttpInfo
     *
     * Fetch Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \com\hydrogen\molecule\Model\WalletResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function getWalletUsingGetWithHttpInfo($wallet_id)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->getWalletUsingGetRequest($wallet_id);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\WalletResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation getWalletUsingGetAsync
     *
     * Fetch Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletUsingGetAsync($wallet_id)
    {
        return $this->getWalletUsingGetAsyncWithHttpInfo($wallet_id)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getWalletUsingGetAsyncWithHttpInfo
     *
     * Fetch Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function getWalletUsingGetAsyncWithHttpInfo($wallet_id)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->getWalletUsingGetRequest($wallet_id);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getWalletUsingGet'
     *
     * @param  string $wallet_id Wallet ID (required)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function getWalletUsingGetRequest($wallet_id)
    {
        // verify the required parameter 'wallet_id' is set
        if ($wallet_id === null || (is_array($wallet_id) && count($wallet_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $wallet_id when calling getWalletUsingGet'
            );
        }

        $resourcePath = '/wallet/{wallet_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($wallet_id !== null) {
            $resourcePath = str_replace(
                '{' . 'wallet_id' . '}',
                ObjectSerializer::toPathValue($wallet_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            
            if($headers['Content-Type'] === 'application/json') {
                // \stdClass has no __toString(), so we should encode it manually
                if ($httpBody instanceof \stdClass) {
                    $httpBody = \GuzzleHttp\json_encode($httpBody);
                }
                // array has no __toString(), so we should encode it manually
                if(is_array($httpBody)) {
                    $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
                }
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'GET',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateWalletUsingPut
     *
     * Update Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_update_params Wallet details to be updated (optional)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return \com\hydrogen\molecule\Model\WalletResponse
     */
    public function updateWalletUsingPut($wallet_id, $wallet_update_params = null)
    {
        list($response) = $this->updateWalletUsingPutWithHttpInfo($wallet_id, $wallet_update_params);
        return $response;
    }

    /**
     * Operation updateWalletUsingPutWithHttpInfo
     *
     * Update Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_update_params Wallet details to be updated (optional)
     *
     * @throws \com\hydrogen\molecule\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of \com\hydrogen\molecule\Model\WalletResponse, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateWalletUsingPutWithHttpInfo($wallet_id, $wallet_update_params = null)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->updateWalletUsingPutRequest($wallet_id, $wallet_update_params);

        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
                );
            }

            $statusCode = $response->getStatusCode();

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    $response->getBody()
                );
            }

            $responseBody = $response->getBody();
            if ($returnType === '\SplFileObject') {
                $content = $responseBody; //stream goes to serializer
            } else {
                $content = $responseBody->getContents();
                if ($returnType !== 'string') {
                    $content = json_decode($content);
                }
            }

            return [
                ObjectSerializer::deserialize($content, $returnType, []),
                $response->getStatusCode(),
                $response->getHeaders()
            ];

        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\WalletResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\com\hydrogen\molecule\Model\ErrorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }

    /**
     * Operation updateWalletUsingPutAsync
     *
     * Update Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_update_params Wallet details to be updated (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateWalletUsingPutAsync($wallet_id, $wallet_update_params = null)
    {
        return $this->updateWalletUsingPutAsyncWithHttpInfo($wallet_id, $wallet_update_params)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateWalletUsingPutAsyncWithHttpInfo
     *
     * Update Wallet details
     *
     * @param  string $wallet_id Wallet ID (required)
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_update_params Wallet details to be updated (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Promise\PromiseInterface
     */
    public function updateWalletUsingPutAsyncWithHttpInfo($wallet_id, $wallet_update_params = null)
    {
        $returnType = '\com\hydrogen\molecule\Model\WalletResponse';
        $request = $this->updateWalletUsingPutRequest($wallet_id, $wallet_update_params);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    $responseBody = $response->getBody();
                    if ($returnType === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                        if ($returnType !== 'string') {
                            $content = json_decode($content);
                        }
                    }

                    return [
                        ObjectSerializer::deserialize($content, $returnType, []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                },
                function ($exception) {
                    $response = $exception->getResponse();
                    $statusCode = $response->getStatusCode();
                    throw new ApiException(
                        sprintf(
                            '[%d] Error connecting to the API (%s)',
                            $statusCode,
                            $exception->getRequest()->getUri()
                        ),
                        $statusCode,
                        $response->getHeaders(),
                        $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'updateWalletUsingPut'
     *
     * @param  string $wallet_id Wallet ID (required)
     * @param  \com\hydrogen\molecule\Model\WalletParams $wallet_update_params Wallet details to be updated (optional)
     *
     * @throws \InvalidArgumentException
     * @return \GuzzleHttp\Psr7\Request
     */
    protected function updateWalletUsingPutRequest($wallet_id, $wallet_update_params = null)
    {
        // verify the required parameter 'wallet_id' is set
        if ($wallet_id === null || (is_array($wallet_id) && count($wallet_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $wallet_id when calling updateWalletUsingPut'
            );
        }

        $resourcePath = '/wallet/{wallet_id}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;


        // path params
        if ($wallet_id !== null) {
            $resourcePath = str_replace(
                '{' . 'wallet_id' . '}',
                ObjectSerializer::toPathValue($wallet_id),
                $resourcePath
            );
        }

        // body params
        $_tempBody = null;
        if (isset($wallet_update_params)) {
            $_tempBody = $wallet_update_params;
        }

        if ($multipart) {
            $headers = $this->headerSelector->selectHeadersForMultipart(
                ['application/json']
            );
        } else {
            $headers = $this->headerSelector->selectHeaders(
                ['application/json'],
                []
            );
        }

        // for model (json/xml)
        if (isset($_tempBody)) {
            // $_tempBody is the method argument, if present
            $httpBody = $_tempBody;
            
            if($headers['Content-Type'] === 'application/json') {
                // \stdClass has no __toString(), so we should encode it manually
                if ($httpBody instanceof \stdClass) {
                    $httpBody = \GuzzleHttp\json_encode($httpBody);
                }
                // array has no __toString(), so we should encode it manually
                if(is_array($httpBody)) {
                    $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
                }
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $multipartContents[] = [
                        'name' => $formParamName,
                        'contents' => $formParamValue
                    ];
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif ($headers['Content-Type'] === 'application/json') {
                $httpBody = \GuzzleHttp\json_encode($formParams);

            } else {
                // for HTTP post (form)
                $httpBody = \GuzzleHttp\Psr7\build_query($formParams);
            }
        }

        // this endpoint requires OAuth (access token)
        if ($this->config->getAccessToken() !== null) {
            $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken();
        }

        $defaultHeaders = [];
        if ($this->config->getUserAgent()) {
            $defaultHeaders['User-Agent'] = $this->config->getUserAgent();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $query = \GuzzleHttp\Psr7\build_query($queryParams);
        return new Request(
            'PUT',
            $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Create http client option
     *
     * @throws \RuntimeException on file opening failure
     * @return array of http client options
     */
    protected function createHttpClientOption()
    {
        $options = [];
        if ($this->config->getDebug()) {
            $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a');
            if (!$options[RequestOptions::DEBUG]) {
                throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile());
            }
        }

        return $options;
    }
}
