<?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 ProfileContext extends InstanceContext
    {
    /**
     * Initialize the ProfileContext
     *
     * @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.
     */
    public function __construct(
        Version $version,
        $storeId,
        $profileId
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

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

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

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


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

        $params = Values::of([
            'traitGroups' =>
                $options['traitGroups'],
        ]);

        $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
        return $this->version->handleRequest('GET', $this->uri, $params, [], $headers, "fetch");
    }

    /**
     * Fetch the ProfileInstance
     *
     
     
     * @param array|Options $options Optional Arguments
     * @return ProfileInstance Fetched ProfileInstance
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetch(array $options = []): ProfileInstance
    {
        $response = $this->_fetch($options);
        return new ProfileInstance(
            $this->version,
            $response->getContent(),
            $this->solution['storeId'],
            $this->solution['profileId']
        );
        
    }

    /**
     * Fetch the ProfileInstance with Metadata
     *
     
     
     * @param array|Options $options Optional Arguments
     * @return ResourceMetadata The Fetched Resource with Metadata
     * @throws TwilioException When an HTTP error occurs.
     */
    public function fetchWithMetadata(array $options = []): ResourceMetadata
    {
        $response = $this->_fetch($options);
        $resource = new ProfileInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId'],
                        $this->solution['profileId']
                    );
        
        return new ResourceMetadata(
            $resource,
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }


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

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

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