<?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\Values;
use Twilio\Version;
use Twilio\ApiV1Version;
use Twilio\InstanceContext;
use Twilio\Http\Response;
use Twilio\Metadata\ResourceMetadata;


class ConfigurationContext extends InstanceContext
    {
    /**
     * Initialize the ConfigurationContext
     *
     * @param Version $version Version that contains the resource
     * @param string $id The unique identifier of the Intelligence Configuration.
     */
    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/Configurations/' . \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 CreateConfiguration201ResponseInstance
     *
     
     * @return CreateConfiguration201ResponseInstance Fetched CreateConfiguration201ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): CreateConfiguration201ResponseInstance
    {
        $response = $this->_fetch();
        return new CreateConfiguration201ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['id']
        );
        
    }

    /**
     * Fetch the CreateConfiguration201ResponseInstance 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 CreateConfiguration201ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['id']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


    /**
     * Helper function for Update
     *
     
     * @param UpdateConfigurationRequest $updateConfigurationRequest
     
     * @return Response Updated Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _update(UpdateConfigurationRequest $updateConfigurationRequest): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' ]);
        $data = $updateConfigurationRequest->toArray();
        return $this->version->handleRequest('PUT', $this->uri, [], $data, $headers, "update");
    }

    /**
     * Update the CreateConfiguration201ResponseInstance
     *
     
     * @param UpdateConfigurationRequest $updateConfigurationRequest
     
     * @return CreateConfiguration201ResponseInstance Updated CreateConfiguration201ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function update(UpdateConfigurationRequest $updateConfigurationRequest): CreateConfiguration201ResponseInstance
    {
        $response = $this->_update( $updateConfigurationRequest);
        return new CreateConfiguration201ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['id']
        );
        
    }

    /**
     * Update the CreateConfiguration201ResponseInstance with Metadata
     *
     
     * @param UpdateConfigurationRequest $updateConfigurationRequest
     
     * @return ResourceMetadata The Updated Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function updateWithMetadata(UpdateConfigurationRequest $updateConfigurationRequest): ResourceMetadata
    {
        $response = $this->_update( $updateConfigurationRequest);
        $resource = new CreateConfiguration201ResponseInstance(
                        $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.ConfigurationContext ' . \implode(' ', $context) . ']';
    }
}
