<?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 DataMappingContext extends InstanceContext
    {
    /**
     * Initialize the DataMappingContext
     *
     * @param Version $version Version that contains the resource
     * @param string $storeId A unique Memory Store ID using Twilio Type ID (TTID) format
     * @param string $dataMappingId A unique DataMapping ID using Twilio Type ID (TTID) format
     */
    public function __construct(
        Version $version,
        $storeId,
        $dataMappingId
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

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

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

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

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


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

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

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

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