<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Twilio Knowledge API
 * APIs for managing knowledge bases and knowledge content for AI-powered applications.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Twilio\Rest\Knowledge\V2;

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


class SearchContext extends InstanceContext
    {
    /**
     * Initialize the SearchContext
     *
     * @param Version $version Version that contains the resource
     * @param string $kbId A unique Knowledge Base ID using Twilio Type ID (TTID) format
     */
    public function __construct(
        Version $version,
        $kbId
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

        // Path Solution
        $this->solution = [
        'kbId' =>
            $kbId,
        ];

        $this->uri = '/KnowledgeBases/' . \rawurlencode($kbId)
        .'/Search';
    }

    /**
     * Helper function for Create
     *
     
     * @param ?KnowledgeSearch $knowledgeSearch
     * @return Response Created Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _create(?KnowledgeSearch $knowledgeSearch = null): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' ]);
        $data = $knowledgeSearch ? $knowledgeSearch->toArray() : [];
        return $this->version->handleRequest('POST', $this->uri, [], $data, $headers, "create");
    }

    /**
     * Create the CreateKnowledgeSearch200ResponseInstance
     *
     
     * @param ?KnowledgeSearch $knowledgeSearch
     * @return CreateKnowledgeSearch200ResponseInstance Created CreateKnowledgeSearch200ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function create(?KnowledgeSearch $knowledgeSearch = null): CreateKnowledgeSearch200ResponseInstance
    {
        $response = $this->_create($knowledgeSearch);
        return new CreateKnowledgeSearch200ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['kbId']
        );
        
    }

    /**
     * Create the CreateKnowledgeSearch200ResponseInstance with Metadata
     *
     
     * @param ?KnowledgeSearch $knowledgeSearch
     * @return ResourceMetadata The Created Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function createWithMetadata(?KnowledgeSearch $knowledgeSearch = null): ResourceMetadata
    {
        $response = $this->_create($knowledgeSearch);
        $resource = new CreateKnowledgeSearch200ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['kbId']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Provide a friendly representation
     *
     * @return string Machine friendly representation
     */
    public function __toString(): string
    {
        $context = [];
        foreach ($this->solution as $key => $value) {
            $context[] = "$key=$value";
        }
        return '[Twilio.Knowledge.V2.SearchContext ' . \implode(' ', $context) . ']';
    }
}
