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

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

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

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

    /**
     * Delete the DeleteTraitGroup202ResponseInstance 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 DeleteTraitGroup202ResponseInstance(
                        $this->version,
                        $response->getContent(),
                        $this->solution['storeId'],
                        $this->solution['traitGroupName']
                    );
        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([
            'includeTraits' =>
                Serialize::booleanToString($options['includeTraits']),
            'pageSize' =>
                $options['pageSize'],
            'pageToken' =>
                $options['pageToken'],
            'orderBy' =>
                $options['orderBy'],
        ]);

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

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


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

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

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

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