<?php

/**
 * This code was generated by
 * ___ _ _ _ _ _    _ ____    ____ ____ _    ____ ____ _  _ ____ ____ ____ ___ __   __
 *  |  | | | | |    | |  | __ |  | |__| | __ | __ |___ |\ | |___ |__/ |__|  | |  | |__/
 *  |  |_|_| | |___ | |__|    |__| |  | |    |__] |___ | \| |___ |  \ |  |  | |__| |  \
 *
 * Twilio Memory API
 * APIs for managing memory stores, profiles, events, and conversational intelligence capabilities.
 *
 * NOTE: This class is auto generated by OpenAPI Generator.
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


namespace Twilio\Rest\Memory\V1;

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 ObservationContext extends InstanceContext
    {
    /**
     * Initialize the ObservationContext
     *
     * @param Version $version Version that contains the resource
     * @param string $storeId A unique Memory Store ID using Twilio Type ID (TTID) format
     * @param string $profileId The unique identifier for the profile using Twilio Type ID (TTID) format.
     * @param string $observationId The observation ID.
     */
    public function __construct(
        Version $version,
        $storeId,
        $profileId,
        $observationId
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

        // Path Solution
        $this->solution = [
        'storeId' =>
            $storeId,
        'profileId' =>
            $profileId,
        'observationId' =>
            $observationId,
        ];

        $this->uri = '/Stores/' . \rawurlencode($storeId)
        .'/Profiles/' . \rawurlencode($profileId)
        .'/Observations/' . \rawurlencode($observationId)
        .'';
    }

    /**
     * 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 DeleteProfileObservation202ResponseInstance
     *
     
     
     
     * @return DeleteProfileObservation202ResponseInstance Deleted DeleteProfileObservation202ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function delete(): DeleteProfileObservation202ResponseInstance
    {
        $response = $this->_delete();
        
        return new DeleteProfileObservation202ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId'],
            $this->solution['profileId'],
            $this->solution['observationId']
        );
    }

    /**
     * Delete the DeleteProfileObservation202ResponseInstance with Metadata
     *
     
     
     
     * @return ResourceMetadata The Deleted Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function deleteWithMetadata(): ResourceMetadata
    {
        $response = $this->_delete();
        
        $resource = new DeleteProfileObservation202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId'],
                        $this->solution['profileId'],
                        $this->solution['observationId']
                    );
        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 ObservationInfoInstance
     *
     
     
     
     * @return ObservationInfoInstance Fetched ObservationInfoInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): ObservationInfoInstance
    {
        $response = $this->_fetch();
        return new ObservationInfoInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId'],
            $this->solution['profileId'],
            $this->solution['observationId']
        );
        
    }

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


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

    /**
     * Patch the PatchProfileObservation202ResponseInstance
     *
     
     
     
     * @param ObservationCore $observationCore
     
     * @return PatchProfileObservation202ResponseInstance Patchd PatchProfileObservation202ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patch(ObservationCore $observationCore): PatchProfileObservation202ResponseInstance
    {
        $response = $this->_patch( $observationCore);
        return new PatchProfileObservation202ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId'],
            $this->solution['profileId'],
            $this->solution['observationId']
        );
        
    }

    /**
     * Patch the PatchProfileObservation202ResponseInstance with Metadata
     *
     
     
     
     * @param ObservationCore $observationCore
     
     * @return ResourceMetadata The Patchd Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patchWithMetadata(ObservationCore $observationCore): ResourceMetadata
    {
        $response = $this->_patch( $observationCore);
        $resource = new PatchProfileObservation202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId'],
                        $this->solution['profileId'],
                        $this->solution['observationId']
                    );
        
        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.Memory.V1.ObservationContext ' . \implode(' ', $context) . ']';
    }
}
