<?php
/**
 * ServiceServiceGroupsApi
 * PHP version 8.1
 *
 * @category Class
 * @package  StevenBuehner\ChurchTools
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */

/**
 * ChurchTools REST API
 *
 * The ChurchTools REST API is the best entry point for developers to access ChurchTools. <br><br> **Authentication:** You need to be authorized to use some endpoints. Those endpoints are marked by a gray lock symbol. If you view the documentation, while you are logged into ChurchTools, all requests are already authorized. If you want to authorized a request, you need to provide a `Login Token` as `Authorization` header in the format `Authorization: Login<token>` or send a valid cookie. You can use the green \"Authorize\" dialog to enter those details and see how a request would look like in detail. <br><br> **Missing Endpoints:** Not all features are yet available by our new REST API. This documentation will grow in the future. We are working hard to add new endpoints with every ChurchTools version. The documentation will always show only those endpoints you can use with your ChurchTools installation.
 *
 * The version of the OpenAPI document: 0.1.0
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.21.0
 */

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

namespace StevenBuehner\ChurchTools\Api;

use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Client;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\ClientInterface;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Exception\ConnectException;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Exception\RequestException;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\MultipartStream;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\RequestOptions;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\Psr\Http\Message\RequestInterface;
use StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\Psr\Http\Message\ResponseInterface;
use StevenBuehner\ChurchTools\ApiException;
use StevenBuehner\ChurchTools\Configuration;
use StevenBuehner\ChurchTools\FormDataProcessor;
use StevenBuehner\ChurchTools\HeaderSelector;
use StevenBuehner\ChurchTools\ObjectSerializer;

/**
 * ServiceServiceGroupsApi Class Doc Comment
 *
 * @category Class
 * @package  StevenBuehner\ChurchTools
 * @author   OpenAPI Generator team
 * @link     https://openapi-generator.tech
 */
class ServiceServiceGroupsApi
{
    /**
     * @var ClientInterface
     */
    protected $client;

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

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

    /**
     * @var int Host index
     */
    protected $hostIndex;

    /** @var string[] $contentTypes **/
    public const contentTypes = [
        'declineServiceRequestById' => [
            'application/json',
        ],
        'getOpenServiceRequestsForPerson' => [
            'application/json',
        ],
        'getService' => [
            'application/json',
        ],
        'getServiceGroup' => [
            'application/json',
        ],
        'getServiceGroups' => [
            'application/json',
        ],
        'getServiceRequestById' => [
            'application/json',
        ],
        'getServices' => [
            'application/json',
        ],
        'undoServiceRequestById' => [
            'application/json',
        ],
        'updateServiceRequestById' => [
            'application/json',
        ],
    ];

    /**
     * @param ClientInterface $client
     * @param Configuration   $config
     * @param HeaderSelector  $selector
     * @param int             $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
     */
    public function __construct(
        ?ClientInterface $client = null,
        ?Configuration $config = null,
        ?HeaderSelector $selector = null,
        int $hostIndex = 0
    ) {
        $this->client = $client ?: new Client();
        $this->config = $config ?: Configuration::getDefaultConfiguration();
        $this->headerSelector = $selector ?: new HeaderSelector();
        $this->hostIndex = $hostIndex;
    }

    /**
     * Set the host index
     *
     * @param int $hostIndex Host index (required)
     */
    public function setHostIndex($hostIndex): void
    {
        $this->hostIndex = $hostIndex;
    }

    /**
     * Get the host index
     *
     * @return int Host index
     */
    public function getHostIndex()
    {
        return $this->hostIndex;
    }

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

    /**
     * Operation declineServiceRequestById
     *
     * Decline a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string|null $comment Comment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['declineServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return void
     */
    public function declineServiceRequestById($person_id, $request_id, $comment = null, string $contentType = self::contentTypes['declineServiceRequestById'][0])
    {
        $this->declineServiceRequestByIdWithHttpInfo($person_id, $request_id, $comment, $contentType);
    }

    /**
     * Operation declineServiceRequestByIdWithHttpInfo
     *
     * Decline a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string|null $comment Comment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['declineServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of null, HTTP status code, HTTP response headers (array of strings)
     */
    public function declineServiceRequestByIdWithHttpInfo($person_id, $request_id, $comment = null, string $contentType = self::contentTypes['declineServiceRequestById'][0])
    {
        $request = $this->declineServiceRequestByIdRequest($person_id, $request_id, $comment, $contentType);

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

            $statusCode = $response->getStatusCode();


            return [null, $statusCode, $response->getHeaders()];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation declineServiceRequestByIdAsync
     *
     * Decline a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string|null $comment Comment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['declineServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function declineServiceRequestByIdAsync($person_id, $request_id, $comment = null, string $contentType = self::contentTypes['declineServiceRequestById'][0])
    {
        return $this->declineServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $comment, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation declineServiceRequestByIdAsyncWithHttpInfo
     *
     * Decline a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string|null $comment Comment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['declineServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function declineServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $comment = null, string $contentType = self::contentTypes['declineServiceRequestById'][0])
    {
        $returnType = '';
        $request = $this->declineServiceRequestByIdRequest($person_id, $request_id, $comment, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    return [null, $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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'declineServiceRequestById'
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string|null $comment Comment (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['declineServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function declineServiceRequestByIdRequest($person_id, $request_id, $comment = null, string $contentType = self::contentTypes['declineServiceRequestById'][0])
    {

        // verify the required parameter 'person_id' is set
        if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $person_id when calling declineServiceRequestById'
            );
        }

        // verify the required parameter 'request_id' is set
        if ($request_id === null || (is_array($request_id) && count($request_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $request_id when calling declineServiceRequestById'
            );
        }



        $resourcePath = '/persons/{personId}/servicerequests/{requestId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $comment,
            'comment', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);


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


        $headers = $this->headerSelector->selectHeaders(
            ['text/plain', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'DELETE',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getOpenServiceRequestsForPerson
     *
     * Get all service requests for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  bool|null $get_all_in_future If set to true, all service requests in future are returned (no matter which state). Otherwise (default) open requests from past and future are returned. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getOpenServiceRequestsForPerson'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response|string
     */
    public function getOpenServiceRequestsForPerson($person_id, $get_all_in_future = null, string $contentType = self::contentTypes['getOpenServiceRequestsForPerson'][0])
    {
        list($response) = $this->getOpenServiceRequestsForPersonWithHttpInfo($person_id, $get_all_in_future, $contentType);
        return $response;
    }

    /**
     * Operation getOpenServiceRequestsForPersonWithHttpInfo
     *
     * Get all service requests for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  bool|null $get_all_in_future If set to true, all service requests in future are returned (no matter which state). Otherwise (default) open requests from past and future are returned. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getOpenServiceRequestsForPerson'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response|string, HTTP status code, HTTP response headers (array of strings)
     */
    public function getOpenServiceRequestsForPersonWithHttpInfo($person_id, $get_all_in_future = null, string $contentType = self::contentTypes['getOpenServiceRequestsForPerson'][0])
    {
        $request = $this->getOpenServiceRequestsForPersonRequest($person_id, $get_all_in_future, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response',
                        $request,
                        $response,
                    );
                case 401:
                    return $this->handleResponseWithDataType(
                        'string',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getOpenServiceRequestsForPersonAsync
     *
     * Get all service requests for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  bool|null $get_all_in_future If set to true, all service requests in future are returned (no matter which state). Otherwise (default) open requests from past and future are returned. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getOpenServiceRequestsForPerson'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getOpenServiceRequestsForPersonAsync($person_id, $get_all_in_future = null, string $contentType = self::contentTypes['getOpenServiceRequestsForPerson'][0])
    {
        return $this->getOpenServiceRequestsForPersonAsyncWithHttpInfo($person_id, $get_all_in_future, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getOpenServiceRequestsForPersonAsyncWithHttpInfo
     *
     * Get all service requests for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  bool|null $get_all_in_future If set to true, all service requests in future are returned (no matter which state). Otherwise (default) open requests from past and future are returned. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getOpenServiceRequestsForPerson'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getOpenServiceRequestsForPersonAsyncWithHttpInfo($person_id, $get_all_in_future = null, string $contentType = self::contentTypes['getOpenServiceRequestsForPerson'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetOpenServiceRequestsForPerson200Response';
        $request = $this->getOpenServiceRequestsForPersonRequest($person_id, $get_all_in_future, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getOpenServiceRequestsForPerson'
     *
     * @param  int $person_id ID of person (required)
     * @param  bool|null $get_all_in_future If set to true, all service requests in future are returned (no matter which state). Otherwise (default) open requests from past and future are returned. (optional)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getOpenServiceRequestsForPerson'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getOpenServiceRequestsForPersonRequest($person_id, $get_all_in_future = null, string $contentType = self::contentTypes['getOpenServiceRequestsForPerson'][0])
    {

        // verify the required parameter 'person_id' is set
        if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $person_id when calling getOpenServiceRequestsForPerson'
            );
        }



        $resourcePath = '/persons/{personId}/servicerequests';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $get_all_in_future,
            'getAllInFuture', // param base name
            'boolean', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);


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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', 'text/plain', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getService
     *
     * 
     *
     * @param  string $service_id service_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getService'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetService200Response
     */
    public function getService($service_id, string $contentType = self::contentTypes['getService'][0])
    {
        list($response) = $this->getServiceWithHttpInfo($service_id, $contentType);
        return $response;
    }

    /**
     * Operation getServiceWithHttpInfo
     *
     * 
     *
     * @param  string $service_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getService'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetService200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getServiceWithHttpInfo($service_id, string $contentType = self::contentTypes['getService'][0])
    {
        $request = $this->getServiceRequest($service_id, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetService200Response',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetService200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetService200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getServiceAsync
     *
     * 
     *
     * @param  string $service_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getService'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceAsync($service_id, string $contentType = self::contentTypes['getService'][0])
    {
        return $this->getServiceAsyncWithHttpInfo($service_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getServiceAsyncWithHttpInfo
     *
     * 
     *
     * @param  string $service_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getService'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceAsyncWithHttpInfo($service_id, string $contentType = self::contentTypes['getService'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetService200Response';
        $request = $this->getServiceRequest($service_id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getService'
     *
     * @param  string $service_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getService'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getServiceRequest($service_id, string $contentType = self::contentTypes['getService'][0])
    {

        // verify the required parameter 'service_id' is set
        if ($service_id === null || (is_array($service_id) && count($service_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $service_id when calling getService'
            );
        }


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



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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getServiceGroup
     *
     * 
     *
     * @param  string $service_group_id service_group_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroup'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServiceGroup200Response
     */
    public function getServiceGroup($service_group_id, string $contentType = self::contentTypes['getServiceGroup'][0])
    {
        list($response) = $this->getServiceGroupWithHttpInfo($service_group_id, $contentType);
        return $response;
    }

    /**
     * Operation getServiceGroupWithHttpInfo
     *
     * 
     *
     * @param  string $service_group_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroup'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServiceGroup200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getServiceGroupWithHttpInfo($service_group_id, string $contentType = self::contentTypes['getServiceGroup'][0])
    {
        $request = $this->getServiceGroupRequest($service_group_id, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServiceGroup200Response',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServiceGroup200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServiceGroup200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getServiceGroupAsync
     *
     * 
     *
     * @param  string $service_group_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceGroupAsync($service_group_id, string $contentType = self::contentTypes['getServiceGroup'][0])
    {
        return $this->getServiceGroupAsyncWithHttpInfo($service_group_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getServiceGroupAsyncWithHttpInfo
     *
     * 
     *
     * @param  string $service_group_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceGroupAsyncWithHttpInfo($service_group_id, string $contentType = self::contentTypes['getServiceGroup'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServiceGroup200Response';
        $request = $this->getServiceGroupRequest($service_group_id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getServiceGroup'
     *
     * @param  string $service_group_id (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroup'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getServiceGroupRequest($service_group_id, string $contentType = self::contentTypes['getServiceGroup'][0])
    {

        // verify the required parameter 'service_group_id' is set
        if ($service_group_id === null || (is_array($service_group_id) && count($service_group_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $service_group_id when calling getServiceGroup'
            );
        }


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



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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getServiceGroups
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroups'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServiceGroups200Response
     */
    public function getServiceGroups(string $contentType = self::contentTypes['getServiceGroups'][0])
    {
        list($response) = $this->getServiceGroupsWithHttpInfo($contentType);
        return $response;
    }

    /**
     * Operation getServiceGroupsWithHttpInfo
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroups'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServiceGroups200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getServiceGroupsWithHttpInfo(string $contentType = self::contentTypes['getServiceGroups'][0])
    {
        $request = $this->getServiceGroupsRequest($contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServiceGroups200Response',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServiceGroups200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServiceGroups200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getServiceGroupsAsync
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceGroupsAsync(string $contentType = self::contentTypes['getServiceGroups'][0])
    {
        return $this->getServiceGroupsAsyncWithHttpInfo($contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getServiceGroupsAsyncWithHttpInfo
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceGroupsAsyncWithHttpInfo(string $contentType = self::contentTypes['getServiceGroups'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServiceGroups200Response';
        $request = $this->getServiceGroupsRequest($contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getServiceGroups'
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceGroups'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getServiceGroupsRequest(string $contentType = self::contentTypes['getServiceGroups'][0])
    {


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





        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getServiceRequestById
     *
     * Get a specific service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string
     */
    public function getServiceRequestById($person_id, $request_id, string $contentType = self::contentTypes['getServiceRequestById'][0])
    {
        list($response) = $this->getServiceRequestByIdWithHttpInfo($person_id, $request_id, $contentType);
        return $response;
    }

    /**
     * Operation getServiceRequestByIdWithHttpInfo
     *
     * Get a specific service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string, HTTP status code, HTTP response headers (array of strings)
     */
    public function getServiceRequestByIdWithHttpInfo($person_id, $request_id, string $contentType = self::contentTypes['getServiceRequestById'][0])
    {
        $request = $this->getServiceRequestByIdRequest($person_id, $request_id, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $request,
                        $response,
                    );
                case 401:
                    return $this->handleResponseWithDataType(
                        'string',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getServiceRequestByIdAsync
     *
     * Get a specific service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceRequestByIdAsync($person_id, $request_id, string $contentType = self::contentTypes['getServiceRequestById'][0])
    {
        return $this->getServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getServiceRequestByIdAsyncWithHttpInfo
     *
     * Get a specific service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, string $contentType = self::contentTypes['getServiceRequestById'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response';
        $request = $this->getServiceRequestByIdRequest($person_id, $request_id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getServiceRequestById'
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getServiceRequestByIdRequest($person_id, $request_id, string $contentType = self::contentTypes['getServiceRequestById'][0])
    {

        // verify the required parameter 'person_id' is set
        if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $person_id when calling getServiceRequestById'
            );
        }

        // verify the required parameter 'request_id' is set
        if ($request_id === null || (is_array($request_id) && count($request_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $request_id when calling getServiceRequestById'
            );
        }


        $resourcePath = '/persons/{personId}/servicerequests/{requestId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', 'text/plain', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getServices
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServices'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServices200Response
     */
    public function getServices(string $contentType = self::contentTypes['getServices'][0])
    {
        list($response) = $this->getServicesWithHttpInfo($contentType);
        return $response;
    }

    /**
     * Operation getServicesWithHttpInfo
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServices'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServices200Response, HTTP status code, HTTP response headers (array of strings)
     */
    public function getServicesWithHttpInfo(string $contentType = self::contentTypes['getServices'][0])
    {
        $request = $this->getServicesRequest($contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServices200Response',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServices200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServices200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation getServicesAsync
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServices'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServicesAsync(string $contentType = self::contentTypes['getServices'][0])
    {
        return $this->getServicesAsyncWithHttpInfo($contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation getServicesAsyncWithHttpInfo
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServices'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function getServicesAsyncWithHttpInfo(string $contentType = self::contentTypes['getServices'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServices200Response';
        $request = $this->getServicesRequest($contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'getServices'
     *
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['getServices'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function getServicesRequest(string $contentType = self::contentTypes['getServices'][0])
    {


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





        $headers = $this->headerSelector->selectHeaders(
            ['application/json', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'GET',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation undoServiceRequestById
     *
     * Undo last service request action
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['undoServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string
     */
    public function undoServiceRequestById($person_id, $request_id, string $contentType = self::contentTypes['undoServiceRequestById'][0])
    {
        list($response) = $this->undoServiceRequestByIdWithHttpInfo($person_id, $request_id, $contentType);
        return $response;
    }

    /**
     * Operation undoServiceRequestByIdWithHttpInfo
     *
     * Undo last service request action
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['undoServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string, HTTP status code, HTTP response headers (array of strings)
     */
    public function undoServiceRequestByIdWithHttpInfo($person_id, $request_id, string $contentType = self::contentTypes['undoServiceRequestById'][0])
    {
        $request = $this->undoServiceRequestByIdRequest($person_id, $request_id, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $request,
                        $response,
                    );
                case 401:
                    return $this->handleResponseWithDataType(
                        'string',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation undoServiceRequestByIdAsync
     *
     * Undo last service request action
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['undoServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function undoServiceRequestByIdAsync($person_id, $request_id, string $contentType = self::contentTypes['undoServiceRequestById'][0])
    {
        return $this->undoServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation undoServiceRequestByIdAsyncWithHttpInfo
     *
     * Undo last service request action
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['undoServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function undoServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, string $contentType = self::contentTypes['undoServiceRequestById'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response';
        $request = $this->undoServiceRequestByIdRequest($person_id, $request_id, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'undoServiceRequestById'
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['undoServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function undoServiceRequestByIdRequest($person_id, $request_id, string $contentType = self::contentTypes['undoServiceRequestById'][0])
    {

        // verify the required parameter 'person_id' is set
        if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $person_id when calling undoServiceRequestById'
            );
        }

        // verify the required parameter 'request_id' is set
        if ($request_id === null || (is_array($request_id) && count($request_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $request_id when calling undoServiceRequestById'
            );
        }


        $resourcePath = '/persons/{personId}/servicerequests/{requestId}/undo';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', 'text/plain', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'POST',
            $operationHost . $resourcePath . ($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation updateServiceRequestById
     *
     * Agree to a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  \StevenBuehner\ChurchTools\Model\UpdateServiceRequestByIdRequest $update_service_request_by_id_request Send the agreed state and optionally a comment. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string
     */
    public function updateServiceRequestById($person_id, $request_id, $update_service_request_by_id_request, string $contentType = self::contentTypes['updateServiceRequestById'][0])
    {
        list($response) = $this->updateServiceRequestByIdWithHttpInfo($person_id, $request_id, $update_service_request_by_id_request, $contentType);
        return $response;
    }

    /**
     * Operation updateServiceRequestByIdWithHttpInfo
     *
     * Agree to a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  \StevenBuehner\ChurchTools\Model\UpdateServiceRequestByIdRequest $update_service_request_by_id_request Send the agreed state and optionally a comment. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateServiceRequestById'] to see the possible values for this operation
     *
     * @throws \StevenBuehner\ChurchTools\ApiException on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     * @return array of \StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response|string, HTTP status code, HTTP response headers (array of strings)
     */
    public function updateServiceRequestByIdWithHttpInfo($person_id, $request_id, $update_service_request_by_id_request, string $contentType = self::contentTypes['updateServiceRequestById'][0])
    {
        $request = $this->updateServiceRequestByIdRequest($person_id, $request_id, $update_service_request_by_id_request, $contentType);

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

            $statusCode = $response->getStatusCode();


            switch($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $request,
                        $response,
                    );
                case 401:
                    return $this->handleResponseWithDataType(
                        'string',
                        $request,
                        $response,
                    );
            }

            

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

            return $this->handleResponseWithDataType(
                '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
                case 401:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'string',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    throw $e;
            }
        

            throw $e;
        }
    }

    /**
     * Operation updateServiceRequestByIdAsync
     *
     * Agree to a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  \StevenBuehner\ChurchTools\Model\UpdateServiceRequestByIdRequest $update_service_request_by_id_request Send the agreed state and optionally a comment. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function updateServiceRequestByIdAsync($person_id, $request_id, $update_service_request_by_id_request, string $contentType = self::contentTypes['updateServiceRequestById'][0])
    {
        return $this->updateServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $update_service_request_by_id_request, $contentType)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }

    /**
     * Operation updateServiceRequestByIdAsyncWithHttpInfo
     *
     * Agree to a service request for a person
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  \StevenBuehner\ChurchTools\Model\UpdateServiceRequestByIdRequest $update_service_request_by_id_request Send the agreed state and optionally a comment. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Promise\PromiseInterface
     */
    public function updateServiceRequestByIdAsyncWithHttpInfo($person_id, $request_id, $update_service_request_by_id_request, string $contentType = self::contentTypes['updateServiceRequestById'][0])
    {
        $returnType = '\StevenBuehner\ChurchTools\Model\GetServiceRequestById200Response';
        $request = $this->updateServiceRequestByIdRequest($person_id, $request_id, $update_service_request_by_id_request, $contentType);

        return $this->client
            ->sendAsync($request, $this->createHttpClientOption())
            ->then(
                function ($response) use ($returnType) {
                    if ($returnType === '\SplFileObject') {
                        $content = $response->getBody(); //stream goes to serializer
                    } else {
                        $content = (string) $response->getBody();
                        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(),
                        (string) $response->getBody()
                    );
                }
            );
    }

    /**
     * Create request for operation 'updateServiceRequestById'
     *
     * @param  int $person_id ID of person (required)
     * @param  int $request_id ID of a service request (required)
     * @param  \StevenBuehner\ChurchTools\Model\UpdateServiceRequestByIdRequest $update_service_request_by_id_request Send the agreed state and optionally a comment. (required)
     * @param  string $contentType The value for the Content-Type header. Check self::contentTypes['updateServiceRequestById'] to see the possible values for this operation
     *
     * @throws \InvalidArgumentException
     * @return \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Psr7\Request
     */
    public function updateServiceRequestByIdRequest($person_id, $request_id, $update_service_request_by_id_request, string $contentType = self::contentTypes['updateServiceRequestById'][0])
    {

        // verify the required parameter 'person_id' is set
        if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $person_id when calling updateServiceRequestById'
            );
        }

        // verify the required parameter 'request_id' is set
        if ($request_id === null || (is_array($request_id) && count($request_id) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $request_id when calling updateServiceRequestById'
            );
        }

        // verify the required parameter 'update_service_request_by_id_request' is set
        if ($update_service_request_by_id_request === null || (is_array($update_service_request_by_id_request) && count($update_service_request_by_id_request) === 0)) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $update_service_request_by_id_request when calling updateServiceRequestById'
            );
        }


        $resourcePath = '/persons/{personId}/servicerequests/{requestId}';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;



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


        $headers = $this->headerSelector->selectHeaders(
            ['application/json', 'text/plain', ],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (isset($update_service_request_by_id_request)) {
            if (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the body
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($update_service_request_by_id_request));
            } else {
                $httpBody = $update_service_request_by_id_request;
            }
        } elseif (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);

            } elseif (stripos($headers['Content-Type'], 'application/json') !== false) {
                # if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = \StevenBuehner\sbChurchtoolsGrouphomepage\Vendor\GuzzleHttp\Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        }

        // this endpoint requires API key authentication
        $apiKey = $this->config->getApiKeyWithPrefix('Authorization');
        if ($apiKey !== null) {
            $headers['Authorization'] = $apiKey;
        }

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

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

        $operationHost = $this->config->getHost();
        $query = ObjectSerializer::buildQuery($queryParams);
        return new Request(
            'PUT',
            $operationHost . $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());
            }
        }

        if ($this->config->getCertFile()) {
            $options[RequestOptions::CERT] = $this->config->getCertFile();
        }

        if ($this->config->getKeyFile()) {
            $options[RequestOptions::SSL_KEY] = $this->config->getKeyFile();
        }

        return $options;
    }

    private function handleResponseWithDataType(
        string $dataType,
        RequestInterface $request,
        ResponseInterface $response
    ): array {
        if ($dataType === '\SplFileObject') {
            $content = $response->getBody(); //stream goes to serializer
        } else {
            $content = (string) $response->getBody();
            if ($dataType !== 'string') {
                try {
                    $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
                } catch (\JsonException $exception) {
                    throw new ApiException(
                        sprintf(
                            'Error JSON decoding server response (%s)',
                            $request->getUri()
                        ),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                        $content
                    );
                }
            }
        }

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

    private function responseWithinRangeCode(
        string $rangeCode,
        int $statusCode
    ): bool {
        $left = (int) ($rangeCode[0].'00');
        $right = (int) ($rangeCode[0].'99');

        return $statusCode >= $left && $statusCode <= $right;
    }
}
