<?php
/**
 * DataHolderApi
 * 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 - ID Directory 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;

/**
 * DataHolderApi Class Doc Comment
 *
 * @category Class
 * @package  Fifa\ConnectId\Sdk\Api
 * @author   Swagger Codegen team
 * @link     https://github.com/swagger-api/swagger-codegen
 */
class DataHolderApi
{
    /**
     * 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 DataHolderApi
     */
    public function setApiClient(\Fifa\ConnectId\Sdk\Api\ApiClient $apiClient)
    {
        $this->apiClient = $apiClient;
        return $this;
    }

    /**
     * Operation dataHolderClaimByPersonfifaid
     *
     * 
     *
     * @param string $person_fifa_id  (required)
     * @param string $x_actor_details Name or identifier of a user invoking the method on API (optional)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return void
     */
    public function dataHolderClaimByPersonfifaid($person_fifa_id, $x_actor_details = null)
    {
        list($response) = $this->dataHolderClaimByPersonfifaidWithHttpInfo($person_fifa_id, $x_actor_details);
        return $response;
    }

    /**
     * Operation dataHolderClaimByPersonfifaidWithHttpInfo
     *
     * 
     *
     * @param string $person_fifa_id  (required)
     * @param string $x_actor_details Name or identifier of a user invoking the method on API (optional)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function dataHolderClaimByPersonfifaidWithHttpInfo($person_fifa_id, $x_actor_details = null)
    {
        // verify the required parameter 'person_fifa_id' is set
        if ($person_fifa_id === null) {
            throw new \InvalidArgumentException('Missing the required parameter $person_fifa_id when calling dataHolderClaimByPersonfifaid');
        }
        // parse inputs
        $resourcePath = "/api/v6/dataholder/claim";
        $httpBody = '';
        $queryParams = [];
        $headerParams = [];
        $formParams = [];
        $_header_accept = $this->apiClient->selectHeaderAccept(['application/json', 'text/json']);
        if (!is_null($_header_accept)) {
            $headerParams['Accept'] = $_header_accept;
        }
        $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]);

        // query params
        if ($person_fifa_id !== null) {
            $queryParams['personFifaId'] = $this->apiClient->getSerializer()->toQueryValue($person_fifa_id);
        }
        // header params
        if ($x_actor_details !== null) {
            $headerParams['X-ActorDetails'] = $this->apiClient->getSerializer()->toHeaderValue($x_actor_details);
        }
        // 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,
                'PUT',
                $queryParams,
                $httpBody,
                $headerParams,
                null,
                '/api/v6/dataholder/claim'
            );

            return [null, $statusCode, $httpHeader];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 301:
                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Fifa\ConnectId\Sdk\Api\Model\PersonType', $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;
        }
    }

    /**
     * Operation dataHolderGetByPersonfifaid
     *
     * 
     *
     * @param string $person_fifa_id  (required)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return string[]
     */
    public function dataHolderGetByPersonfifaid($person_fifa_id)
    {
        list($response) = $this->dataHolderGetByPersonfifaidWithHttpInfo($person_fifa_id);
        return $response;
    }

    /**
     * Operation dataHolderGetByPersonfifaidWithHttpInfo
     *
     * 
     *
     * @param string $person_fifa_id  (required)
     * @throws \Fifa\ConnectId\Sdk\Api\ApiException on non-2xx response
     * @return array of string[], HTTP status code, HTTP response headers (array of strings)
     */
    public function dataHolderGetByPersonfifaidWithHttpInfo($person_fifa_id)
    {
        // verify the required parameter 'person_fifa_id' is set
        if ($person_fifa_id === null) {
            throw new \InvalidArgumentException('Missing the required parameter $person_fifa_id when calling dataHolderGetByPersonfifaid');
        }
        // parse inputs
        $resourcePath = "/api/v6/dataholder/get";
        $httpBody = '';
        $queryParams = [];
        $headerParams = [];
        $formParams = [];
        $_header_accept = $this->apiClient->selectHeaderAccept(['application/json', 'text/json']);
        if (!is_null($_header_accept)) {
            $headerParams['Accept'] = $_header_accept;
        }
        $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType([]);

        // query params
        if ($person_fifa_id !== null) {
            $queryParams['personFifaId'] = $this->apiClient->getSerializer()->toQueryValue($person_fifa_id);
        }
        // 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,
                'GET',
                $queryParams,
                $httpBody,
                $headerParams,
                'string[]',
                '/api/v6/dataholder/get'
            );

            return [$this->apiClient->getSerializer()->deserialize($response, 'string[]', $httpHeader), $statusCode, $httpHeader];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string[]', $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;
        }
    }
}

