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


class StoreContext extends InstanceContext
    {
    /**
     * Initialize the StoreContext
     *
     * @param Version $version Version that contains the resource
     * @param string $storeId A unique Memory Store ID using Twilio Type ID (TTID) format
     */
    public function __construct(
        Version $version,
        $storeId
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

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

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

    /**
     * Delete the DeleteStore202ResponseInstance 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 DeleteStore202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId']
                    );
        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 StoreInstance
     *
     
     * @return StoreInstance Fetched StoreInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(): StoreInstance
    {
        $response = $this->_fetch();
        return new StoreInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId']
        );
        
    }

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


    /**
     * Helper function for Patch
     *
     
     * @param ?PatchStoreRequest $patchStoreRequest
     * @param array|Options $options Optional Arguments
     * @return Response Patchd Response
     * @throws TwilioException When an HTTP error occurs.
     */
    private function _patch(?PatchStoreRequest $patchStoreRequest = null, array $options = []): Response
    {
        
        $options = new Values($options);

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

    /**
     * Patch the PatchStore202ResponseInstance
     *
     
     * @param ?PatchStoreRequest $patchStoreRequest
     * @param array|Options $options Optional Arguments
     * @return PatchStore202ResponseInstance Patchd PatchStore202ResponseInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patch(?PatchStoreRequest $patchStoreRequest = null, array $options = []): PatchStore202ResponseInstance
    {
        $response = $this->_patch($patchStoreRequest, $options);
        return new PatchStore202ResponseInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId']
        );
        
    }

    /**
     * Patch the PatchStore202ResponseInstance with Metadata
     *
     
     * @param ?PatchStoreRequest $patchStoreRequest
     * @param array|Options $options Optional Arguments
     * @return ResourceMetadata The Patchd Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function patchWithMetadata(?PatchStoreRequest $patchStoreRequest = null, array $options = []): ResourceMetadata
    {
        $response = $this->_patch($patchStoreRequest, $options);
        $resource = new PatchStore202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId']
                    );
        
        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.StoreContext ' . \implode(' ', $context) . ']';
    }
}
