<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Twilio - Insights
 * Insights Domain V3 API.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Twilio\Rest\Insights\V3;

use Twilio\Exceptions\TwilioException;
use Twilio\ListResource;
use Twilio\Options;
use Twilio\Values;
use Twilio\Version;
use Twilio\ApiV1Version;
use Twilio\Http\Response;
use Twilio\Metadata\ResourceMetadata;


class QueryList extends ListResource
    {
    /**
     * Construct the QueryList
     *
     * @param Version $version Version that contains the resource
     */
    public function __construct(
        Version $version
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

        // Path Solution
        $this->solution = [
        ];
    }

    /**
     * Helper function for Create
     *
     * @param InsightsQueryRequest $insightsQueryRequest
     
     * @param array|Options $options Optional Arguments
     * @return Response Created Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _create(InsightsQueryRequest $insightsQueryRequest, array $options = []): Response
    {
        
        $uri = '/InsightsDomains/Conversations/Query';
        
        $options = new Values($options);

        $params = Values::of([
            'pageSize' =>
                $options['pageSize'],
        ]);

        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' ]);
        $data = $insightsQueryRequest->toArray();
        return $this->version->handleRequest('POST', $uri, $params, $data, $headers, "create");
    }

    /**
     * Create the InsightsQueryResponseInstance
     *
     * @param InsightsQueryRequest $insightsQueryRequest
     
     * @param array|Options $options Optional Arguments
     * @return InsightsQueryResponseInstance Created InsightsQueryResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function create(InsightsQueryRequest $insightsQueryRequest, array $options = []): InsightsQueryResponseInstance
    {
        $response = $this->_create( $insightsQueryRequest, $options);
        return new InsightsQueryResponseInstance(
            $this->version,
            $response->getContent()
        );
        
    }

    /**
     * Create the InsightsQueryResponseInstance with Metadata
     *
     * @param InsightsQueryRequest $insightsQueryRequest
     
     * @param array|Options $options Optional Arguments
     * @return ResourceMetadata The Created Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function createWithMetadata(InsightsQueryRequest $insightsQueryRequest, array $options = []): ResourceMetadata
    {
        $response = $this->_create( $insightsQueryRequest, $options);
        $resource = new InsightsQueryResponseInstance(
                        $this->version,
                        $response->getContent()
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Helper function for Fetch
     *
     * @param string $pageToken Pagination token
     
     * @return Response Fetched Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _fetch(string $pageToken): Response
    {
        
        $uri = '/InsightsDomains/Conversations/Query';
        
        $params = Values::of([
            'pageToken' =>
                $pageToken,
        ]);

        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
        return $this->version->handleRequest('GET', $uri, $params, [], $headers, "fetch");
    }

    /**
     * Fetch the InsightsQueryResponseInstance
     *
     * @param string $pageToken Pagination token
     
     * @return InsightsQueryResponseInstance Fetched InsightsQueryResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(string $pageToken): InsightsQueryResponseInstance
    {
        $response = $this->_fetch( $pageToken);
        return new InsightsQueryResponseInstance(
            $this->version,
            $response->getContent()
        );
        
    }

    /**
     * Fetch the InsightsQueryResponseInstance with Metadata
     *
     * @param string $pageToken Pagination token
     
     * @return ResourceMetadata The Fetched Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetchWithMetadata(string $pageToken): ResourceMetadata
    {
        $response = $this->_fetch( $pageToken);
        $resource = new InsightsQueryResponseInstance(
                        $this->version,
                        $response->getContent()
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Provide a friendly representation
     *
     * @return string Machine friendly representation
     */
    public function __toString(): string
    {
        return '[Twilio.Insights.V3.QueryList]';
    }
}
