<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Conversation Orchestrator
 * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Twilio\Rest\Conversations\V2;

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 ConversationContext extends InstanceContext
    {
    /**
     * Initialize the ConversationContext
     *
     * @param Version $version Version that contains the resource
     * @param string $sid
     */
    public function __construct(
        Version $version,
        $sid
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

        $this->uri = '/Conversations/' . \rawurlencode($sid)
        .'';
    }

    /**
     * Helper function for Delete
     *
     
     * @param array|Options $options Optional Arguments
     * @return Response Deleted Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _delete(array $options = []): Response
    {
        
        $options = new Values($options);

        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' , 'Idempotency-Key' => $options['idempotencyKey']]);
        return $this->version->handleRequest('DELETE', $this->uri, [], [], $headers, "delete");
    }

    /**
     * Delete the CreateConfiguration202ResponseInstance
     *
     
     * @param array|Options $options Optional Arguments
     * @return CreateConfiguration202ResponseInstance Deleted CreateConfiguration202ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function delete(array $options = []): CreateConfiguration202ResponseInstance
    {
        $response = $this->_delete($options);
        
        return new CreateConfiguration202ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['sid']
        );
    }

    /**
     * Delete the CreateConfiguration202ResponseInstance with Metadata
     *
     
     * @param array|Options $options Optional Arguments
     * @return ResourceMetadata The Deleted Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function deleteWithMetadata(array $options = []): ResourceMetadata
    {
        $response = $this->_delete($options);
        
        $resource = new CreateConfiguration202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['sid']
                    );
        return new ResourceMetadata(
            $resource,
            $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 ListConversationByAccount200ResponseConversationsInstance
     *
     
     * @return ListConversationByAccount200ResponseConversationsInstance Fetched ListConversationByAccount200ResponseConversationsInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): ListConversationByAccount200ResponseConversationsInstance
    {
        $response = $this->_fetch();
        return new ListConversationByAccount200ResponseConversationsInstance(
            $this->version,
            $response->getContent(),
            $this->solution['sid']
        );
        
    }

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


    /**
     * Helper function for Patch
     *
     
     * @param ?PatchConversationByIdRequest $patchConversationByIdRequest The conversation fields to update
     * @return Response Patchd Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _patch(?PatchConversationByIdRequest $patchConversationByIdRequest = null): Response
    {
        
        $headers = Values::of(['Content-Type' => 'application/json', 'Accept' => 'application/json' ]);
        $data = $patchConversationByIdRequest ? $patchConversationByIdRequest->toArray() : [];
        return $this->version->handleRequest('PATCH', $this->uri, [], $data, $headers, "patch");
    }

    /**
     * Patch the ListConversationByAccount200ResponseConversationsInstance
     *
     
     * @param ?PatchConversationByIdRequest $patchConversationByIdRequest The conversation fields to update
     * @return ListConversationByAccount200ResponseConversationsInstance Patchd ListConversationByAccount200ResponseConversationsInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patch(?PatchConversationByIdRequest $patchConversationByIdRequest = null): ListConversationByAccount200ResponseConversationsInstance
    {
        $response = $this->_patch($patchConversationByIdRequest);
        return new ListConversationByAccount200ResponseConversationsInstance(
            $this->version,
            $response->getContent(),
            $this->solution['sid']
        );
        
    }

    /**
     * Patch the ListConversationByAccount200ResponseConversationsInstance with Metadata
     *
     
     * @param ?PatchConversationByIdRequest $patchConversationByIdRequest The conversation fields to update
     * @return ResourceMetadata The Patchd Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patchWithMetadata(?PatchConversationByIdRequest $patchConversationByIdRequest = null): ResourceMetadata
    {
        $response = $this->_patch($patchConversationByIdRequest);
        $resource = new ListConversationByAccount200ResponseConversationsInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['sid']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


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

    /**
     * Update the ListConversationByAccount200ResponseConversationsInstance
     *
     
     * @param ?UpdateConversationByIdRequest $updateConversationByIdRequest The conversation to update
     * @return ListConversationByAccount200ResponseConversationsInstance Updated ListConversationByAccount200ResponseConversationsInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function update(?UpdateConversationByIdRequest $updateConversationByIdRequest = null): ListConversationByAccount200ResponseConversationsInstance
    {
        $response = $this->_update($updateConversationByIdRequest);
        return new ListConversationByAccount200ResponseConversationsInstance(
            $this->version,
            $response->getContent(),
            $this->solution['sid']
        );
        
    }

    /**
     * Update the ListConversationByAccount200ResponseConversationsInstance with Metadata
     *
     
     * @param ?UpdateConversationByIdRequest $updateConversationByIdRequest The conversation to update
     * @return ResourceMetadata The Updated Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function updateWithMetadata(?UpdateConversationByIdRequest $updateConversationByIdRequest = null): ResourceMetadata
    {
        $response = $this->_update($updateConversationByIdRequest);
        $resource = new ListConversationByAccount200ResponseConversationsInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['sid']
                    );
        
        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.Conversations.V2.ConversationContext ' . \implode(' ', $context) . ']';
    }
}
