<?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;
use Twilio\Serialize;


class IdentifierContext extends InstanceContext
    {
    /**
     * Initialize the IdentifierContext
     *
     * @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 $idType Identifier type configured for the service (for example `email`, `phone`, or `externalId`).
     */
    public function __construct(
        Version $version,
        $storeId,
        $profileId,
        $idType
    ) {
        $apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
        parent::__construct($apiV1Version);

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

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

    /**
     * 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);

        $params = Values::of([
            'removeAll' =>
                Serialize::booleanToString($options['removeAll']),
        ]);

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

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

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

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


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

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

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