<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Twilio Conversational Intelligence API
 * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results.  * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations.  * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Twilio\Rest\Intelligence\V3;

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


class OperatorContext extends InstanceContext
    {
    /**
     * Initialize the OperatorContext
     *
     * @param Version $version Version that contains the resource
     * @param string $id The unique identifier (TTID) of the Language Operator.
     */
    public function __construct(
        Version $version,
        $id
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

        $this->uri = '/ControlPlane/Operators/' . \rawurlencode($id)
        .'';
    }

    /**
     * Helper function for Delete
     *
     
     * @return Response Deleted Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _delete(): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
        return $this->version->handleRequest('DELETE', $this->uri, [], [], $headers, "delete");
    }

    /**
     * Delete the Instance
     *
     
     * @return bool True if delete succeeds, false otherwise
     * @throws TwilioException When an HTTP error occurs.
     */
    public function delete(): bool
    {
        $response = $this->_delete();
        
        return true;
    }

    /**
     * Delete the Instance with Metadata
     *
     
     * @return ResourceMetadata The Deleted Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function deleteWithMetadata(): ResourceMetadata
    {
        $response = $this->_delete();
        
        
        return new ResourceMetadata(
            null,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Helper function for Fetch
     *
     
     * @return Response Fetched Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _fetch(): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
        return $this->version->handleRequest('GET', $this->uri, [], [], $headers, "fetch");
    }

    /**
     * Fetch the CreateOperator201ResponseInstance
     *
     
     * @return CreateOperator201ResponseInstance Fetched CreateOperator201ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): CreateOperator201ResponseInstance
    {
        $response = $this->_fetch();
        return new CreateOperator201ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['id']
        );
        
    }

    /**
     * Fetch the CreateOperator201ResponseInstance with Metadata
     *
     
     * @return ResourceMetadata The Fetched Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetchWithMetadata(): ResourceMetadata
    {
        $response = $this->_fetch();
        $resource = new CreateOperator201ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['id']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Helper function for Update
     *
     
     * @param LanguageOperator $languageOperator Full replacement of a Language Operator configuration
     
     * @param array|Options $options Optional Arguments
     * @return Response Updated Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _update(LanguageOperator $languageOperator, array $options = []): Response
    {
        
        $options = new Values($options);

        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' , 'If-Match' => $options['ifMatch']]);
        $data = $languageOperator->toArray();
        return $this->version->handleRequest('PUT', $this->uri, [], $data, $headers, "update");
    }

    /**
     * Update the CreateOperator201ResponseInstance
     *
     
     * @param LanguageOperator $languageOperator Full replacement of a Language Operator configuration
     
     * @param array|Options $options Optional Arguments
     * @return CreateOperator201ResponseInstance Updated CreateOperator201ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function update(LanguageOperator $languageOperator, array $options = []): CreateOperator201ResponseInstance
    {
        $response = $this->_update( $languageOperator, $options);
        return new CreateOperator201ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['id']
        );
        
    }

    /**
     * Update the CreateOperator201ResponseInstance with Metadata
     *
     
     * @param LanguageOperator $languageOperator Full replacement of a Language Operator configuration
     
     * @param array|Options $options Optional Arguments
     * @return ResourceMetadata The Updated Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function updateWithMetadata(LanguageOperator $languageOperator, array $options = []): ResourceMetadata
    {
        $response = $this->_update( $languageOperator, $options);
        $resource = new CreateOperator201ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['id']
                    );
        
        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.Intelligence.V3.OperatorContext ' . \implode(' ', $context) . ']';
    }
}
