<?php

declare(strict_types=1);

namespace NoahVet\Reef\Jane\Endpoint;

class SearchVeterinaryGroup extends \NoahVet\Reef\Jane\Runtime\Client\BaseEndpoint implements \NoahVet\Reef\Jane\Runtime\Client\Endpoint
{
    use \NoahVet\Reef\Jane\Runtime\Client\EndpointTrait;

    /**
     * Search on Veterinary Groups.
     * A veterinary group is a company, enterprise, association identifiable by a legalCode.
     *
     * @param array $queryParameters {
     *
     * @var int   $page the page of items to collect a part of result set
     * @var int   $limit the maximum number of items to collect a part of result set
     * @var array $id[] Filter by id
     * @var array $legalStructureId[] Filter by legalStructureId
     * @var array $veterinaryEstablishmentId[] Filter by veterinaryEstablishmentId
     * @var array $veterinaryEstablishmentMemberId[] Filter by veterinaryEstablishmentMemberId
     * @var array $vguUserId[] Filter by userId of Veterinary Group User
     * @var array $entitled[] Filter by entitled
     * @var array $groupCode[] Filter by groupCode
     * @var array $status[]
     * @var array $vguUser[] Filter by jobTitle of veterinary group user
     * @var array $fromCreatedDate[] Returns results whose `createdDate` is greater than or equal to the specified value.
     *            Example for 2022-03-15 value :
     *
     * |----Jan---|----Feb---|----Mar---|----Apr----|----May----|
     * |----------Filtered---------|----------Returned----------|
     * @var array $fromUpdatedDate[] Returns results whose `updatedDate` is greater than or equal to the specified value.
     *            Example for 2022-03-15 value :
     *
     * |----Jan---|----Feb---|----Mar---|----Apr----|----May----|
     * |----------Filtered---------|----------Returned----------|
     * @var array $toCreatedDate[] Returns results whose `createdDate` is lower than or equal to the specified value.
     *            Example for 2022-03-15 value :
     *
     * |----Jan---|----Feb---|----Mar---|----Apr----|----May----|
     * |-----------Returned--------|---------Filtered-----------|
     * @var array $toUpdatedDate[] Returns results whose `updatedDate` is lower than or equal to the specified value.
     *            Example for 2022-03-15 value :
     *
     * |----Jan---|----Feb---|----Mar---|----Apr----|----May----|
     * |-----------Returned--------|---------Filtered-----------|
     * @var string $sortCreatedDate sort by createdDate
     * @var string $sortEntryNumber sort by entryNumber
     * @var string $sortGroupCode sort by groupCode
     * @var string $sortName sort by name
     * @var string $sortType sort by type
     * @var string $sortUpdatedDate Sort by updatedDate.
     *             }
     *
     * @param array $headerParameters {
     *
     * @var string $Accept-Language The current locale.
     *             }
     */
    public function __construct(\NoahVet\Reef\Jane\Model\VeterinaryGroupSearchRequest $requestBody, array $queryParameters = [], array $headerParameters = [])
    {
        $this->body = $requestBody;
        $this->queryParameters = $queryParameters;
        $this->headerParameters = $headerParameters;
    }

    public function getMethod(): string
    {
        return 'POST';
    }

    public function getUri(): string
    {
        return '/v1/veterinary_groups/search';
    }

    public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
    {
        if ($this->body instanceof \NoahVet\Reef\Jane\Model\VeterinaryGroupSearchRequest) {
            return [['Content-Type' => ['application/json']], $serializer->serialize($this->body, 'json')];
        }

        return [[], null];
    }

    public function getExtraHeaders(): array
    {
        return ['Accept' => ['application/json']];
    }

    public function getAuthenticationScopes(): array
    {
        return ['BearerAuth'];
    }

    protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
    {
        $optionsResolver = parent::getQueryOptionsResolver();
        $optionsResolver->setDefined(['page', 'limit', 'id', 'legalStructureId', 'veterinaryEstablishmentId', 'veterinaryEstablishmentMemberId', 'vguUserId', 'entitled', 'groupCode', 'status', 'vguUser', 'fromCreatedDate', 'fromUpdatedDate', 'toCreatedDate', 'toUpdatedDate', 'sortCreatedDate', 'sortEntryNumber', 'sortGroupCode', 'sortName', 'sortType', 'sortUpdatedDate']);
        $optionsResolver->setRequired([]);
        $optionsResolver->setDefaults([]);
        $optionsResolver->addAllowedTypes('page', ['int']);
        $optionsResolver->addAllowedTypes('limit', ['int']);
        $optionsResolver->addAllowedTypes('id', ['array']);
        $optionsResolver->addAllowedTypes('legalStructureId', ['array']);
        $optionsResolver->addAllowedTypes('veterinaryEstablishmentId', ['array']);
        $optionsResolver->addAllowedTypes('veterinaryEstablishmentMemberId', ['array']);
        $optionsResolver->addAllowedTypes('vguUserId', ['array']);
        $optionsResolver->addAllowedTypes('entitled', ['array']);
        $optionsResolver->addAllowedTypes('groupCode', ['array']);
        $optionsResolver->addAllowedTypes('status', ['array']);
        $optionsResolver->addAllowedTypes('vguUser', ['array']);
        $optionsResolver->addAllowedTypes('fromCreatedDate', ['array']);
        $optionsResolver->addAllowedTypes('fromUpdatedDate', ['array', 'null']);
        $optionsResolver->addAllowedTypes('toCreatedDate', ['array', 'null']);
        $optionsResolver->addAllowedTypes('toUpdatedDate', ['array', 'null']);
        $optionsResolver->addAllowedTypes('sortCreatedDate', ['string']);
        $optionsResolver->addAllowedTypes('sortEntryNumber', ['string']);
        $optionsResolver->addAllowedTypes('sortGroupCode', ['string']);
        $optionsResolver->addAllowedTypes('sortName', ['string']);
        $optionsResolver->addAllowedTypes('sortType', ['string']);
        $optionsResolver->addAllowedTypes('sortUpdatedDate', ['string']);

        return $optionsResolver;
    }

    protected function getHeadersOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
    {
        $optionsResolver = parent::getHeadersOptionsResolver();
        $optionsResolver->setDefined(['Accept-Language']);
        $optionsResolver->setRequired([]);
        $optionsResolver->setDefaults([]);
        $optionsResolver->addAllowedTypes('Accept-Language', ['string']);

        return $optionsResolver;
    }

    /**
     * @return \NoahVet\Reef\Jane\Model\VeterinaryGroupResponse[]
     *
     * @throws \NoahVet\Reef\Jane\Exception\SearchVeterinaryGroupBadRequestException
     * @throws \NoahVet\Reef\Jane\Exception\UnexpectedStatusCodeException
     */
    protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
    {
        $status = $response->getStatusCode();
        $body = (string) $response->getBody();
        if ((null === $contentType) === false && (200 === $status && false !== \mb_strpos($contentType, 'application/json'))) {
            return $serializer->deserialize($body, 'NoahVet\\Reef\\Jane\\Model\\VeterinaryGroupResponse[]', 'json');
        }
        if ((null === $contentType) === false && (206 === $status && false !== \mb_strpos($contentType, 'application/json'))) {
            return $serializer->deserialize($body, 'NoahVet\\Reef\\Jane\\Model\\VeterinaryGroupResponse[]', 'json');
        }
        if (400 === $status) {
            throw new \NoahVet\Reef\Jane\Exception\SearchVeterinaryGroupBadRequestException($response);
        }
        throw new \NoahVet\Reef\Jane\Exception\UnexpectedStatusCodeException($status, $body);
    }
}
