<?php
/**
 * HashApi
 * PHP version 5
 *
 * @category Class
 * @package  Fifa\ConnectId\Sdk\Api
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */

/**
 * FIFA Connect ID - Hashing V6
 *
 * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
 *
 * OpenAPI spec version: v6
 * 
 * Generated by: https://github.com/swagger-api/swagger-codegen.git
 *
 */

/**
 * 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 Fifa\ConnectId\Sdk\Api\Resource;

use \Fifa\ConnectId\Sdk\Api\ApiClient;
use \Fifa\ConnectId\Sdk\Api\ApiException;
use \Fifa\ConnectId\Sdk\Api\Configuration;
use \Fifa\ConnectId\Sdk\Api\ObjectSerializer;

/**
 * HashApi Class Doc Comment
 *
 * @category Class
 * @package  Fifa\ConnectId\Sdk\Api
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class HashApi
{
    /**
     * API Client
     *
     * @var \Fifa\ConnectId\Sdk\Api\ApiClient instance of the ApiClient
     */
    protected $apiClient;

    /**
     * Constructor
     *
     * @param \Fifa\ConnectId\Sdk\Api\ApiClient|null $apiClient The api client to use
     */
    public function __construct(\Fifa\ConnectId\Sdk\Api\ApiClient $apiClient = null)
    {
        if ($apiClient === null) {
            $apiClient = new ApiClient();
        }

        $this->apiClient = $apiClient;
    }

    /**
     * Get API client
     *
     * @return \Fifa\ConnectId\Sdk\Api\ApiClient get the API client
     */
    public function getApiClient()
    {
        return $this->apiClient;
    }

    /**
     * Set the API client
     *
     * @param \Fifa\ConnectId\Sdk\Api\ApiClient $apiClient set the API client
     *
     * @return HashApi
     */
    public function setApiClient(\Fifa\ConnectId\Sdk\Api\ApiClient $apiClient)
    {
        $this->apiClient = $apiClient;
        return $this;
    }

    /**
     * Operation hashComputeByRequestFirstnameAndRequestLastnameAndRequestPrefer
     *
     * Computes a collection of hashes of person's first and last name.
     *
     * @param string $last_name &#39;LocalLastName&#39; or &#39;InternationalLastName&#39; of &#39;PersonLocalType&#39; as defined in FIFA Connect Data Standard. (required)
     * @param string $first_name &#39;LocalFirstName&#39; or &#39;InternationalFirstName&#39; of &#39;PersonLocalType&#39; as defined in FIFA Connect Data Standard. (optional)
     * @param string $prefer  (optional)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return \Fifa\ConnectId\Sdk\Api\Model\HashedNameType[]
     */
    public function hashComputeByRequestFirstnameAndRequestLastnameAndRequestPrefer($last_name, $first_name = null, $prefer = null)
    {
        list($response) = $this->hashComputeByRequestFirstnameAndRequestLastnameAndRequestPreferWithHttpInfo($last_name, $first_name, $prefer);
        return $response;
    }

    /**
     * Operation hashComputeByRequestFirstnameAndRequestLastnameAndRequestPreferWithHttpInfo
     *
     * Computes a collection of hashes of person's first and last name.
     *
     * @param string $last_name &#39;LocalLastName&#39; or &#39;InternationalLastName&#39; of &#39;PersonLocalType&#39; as defined in FIFA Connect Data Standard. (required)
     * @param string $first_name &#39;LocalFirstName&#39; or &#39;InternationalFirstName&#39; of &#39;PersonLocalType&#39; as defined in FIFA Connect Data Standard. (optional)
     * @param string $prefer  (optional)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return array of \Fifa\ConnectId\Sdk\Api\Model\HashedNameType[], HTTP status code, HTTP response headers (array of strings)
     */
    public function hashComputeByRequestFirstnameAndRequestLastnameAndRequestPreferWithHttpInfo($last_name, $first_name = null, $prefer = null)
    {
        // verify the required parameter 'last_name' is set
        if ($last_name === null) {
            throw new \InvalidArgumentException('Missing the required parameter $last_name when calling hashComputeByRequestFirstnameAndRequestLastnameAndRequestPrefer');
        }
        // parse inputs
        $resourcePath = "/api/v6/hash/compute";
        $httpBody = '';
        $queryParams = [];
        $headerParams = [];
        $formParams = [];
        $_header_accept = $this->apiClient->selectHeaderAccept(['text/plain', 'application/json', 'text/json']);
        if (!is_null($_header_accept)) {
            $headerParams['Accept'] = $_header_accept;
        }
        $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]);

        // query params
        if ($first_name !== null) {
            $queryParams['firstName'] = $this->apiClient->getSerializer()->toQueryValue($first_name);
        }
        // query params
        if ($last_name !== null) {
            $queryParams['lastName'] = $this->apiClient->getSerializer()->toQueryValue($last_name);
        }
        // header params
        if ($prefer !== null) {
            $headerParams['prefer'] = $this->apiClient->getSerializer()->toHeaderValue($prefer);
        }
        // default format to json
        $resourcePath = str_replace("{format}", "json", $resourcePath);

        // for model (json/xml)
        if (isset($_tempBody)) {
            $httpBody = $_tempBody; // $_tempBody is the method argument, if present
        } elseif (count($formParams) > 0) {
            $httpBody = $formParams; // for HTTP post (form)
        }
        // this endpoint requires OAuth (access token)
        if (strlen($this->apiClient->getConfig()->getAccessToken()) !== 0) {
            $headerParams['Authorization'] = 'Bearer ' . $this->apiClient->getConfig()->getAccessToken();
        }
        // make the API Call
        try {
            list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
                $resourcePath,
                'POST',
                $queryParams,
                $httpBody,
                $headerParams,
                '\Fifa\ConnectId\Sdk\Api\Model\HashedNameType[]',
                '/api/v6/hash/compute'
            );

            return [$this->apiClient->getSerializer()->deserialize($response, '\Fifa\ConnectId\Sdk\Api\Model\HashedNameType[]', $httpHeader), $statusCode, $httpHeader];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Fifa\ConnectId\Sdk\Api\Model\HashedNameType[]', $e->getResponseHeaders());
                    $e->setResponseObject($data);
                    break;
                case 400:
                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Fifa\ConnectId\Sdk\Api\Model\BadRequestResponseType', $e->getResponseHeaders());
                    $e->setResponseObject($data);
                    break;
                case 429:
                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Fifa\ConnectId\Sdk\Api\Model\TooManyRequestsResponseType', $e->getResponseHeaders());
                    $e->setResponseObject($data);
                    break;
            }

            throw $e;
        }
    }
}

