<?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\InstanceResource;
use Twilio\Values;
use Twilio\Version;
use Twilio\ApiV1Version;


/**
 * @property string[] $chunks
 */
class CreateKnowledgeSearch200ResponseInstance extends InstanceResource
{
    /**
     * Initialize the CreateKnowledgeSearch200ResponseInstance
     *
     * @param Version $version Version that contains the resource
     * @param mixed[] $payload The response payload
     * @param string $kbId A unique Knowledge Base ID using Twilio Type ID (TTID) format
     */
    public function __construct(Version $version, array $payload, ?string $kbId = null)
    {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

        // Marshaled Properties
        $this->properties = [
            'chunks' => Values::array_get($payload, 'chunks'),
        ];

        $this->solution = ['kbId' => $kbId ?: ($this->properties['kbId'] ?? null), ];
    }

    /**
     * Generate an instance context for the instance, the context is capable of
     * performing various actions.  All instance actions are proxied to the context
     *
     * @return SearchContext Context for this SearchInstance
     */
    protected function proxy(): SearchContext
    {
        if (!$this->context) {
            $this->context = new SearchContext(
                $this->version,
                $this->solution['kbId']
            );
        }

        return $this->context;
    }

    /**
     * Create the CreateKnowledgeSearch200ResponseInstance
     *
     * @return CreateKnowledgeSearch200ResponseInstance Created CreateKnowledgeSearch200ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function create(): CreateKnowledgeSearch200ResponseInstance
    {

        return $this->proxy()->create();
    }

    /**
     * Magic getter to access properties
     *
     * @param string $name Property to access
     * @return mixed The requested property
     * @throws TwilioException For unknown properties
     */
    public function __get(string $name)
    {
        if (\array_key_exists($name, $this->properties)) {
            return $this->properties[$name];
        }

        if (\property_exists($this, '_' . $name)) {
            $method = 'get' . \ucfirst($name);
            return $this->$method();
        }

        throw new TwilioException('Unknown property: ' . $name);
    }

    /**
     * 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.CreateKnowledgeSearch200ResponseInstance ' . \implode(' ', $context) . ']';
    }
}
