# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

import uuid
from msrest.pipeline import ClientRawResponse

from .. import models


class PlanOperations(object):
    """PlanOperations operations.

    :param client: Client for service requests.
    :param config: Configuration of service client.
    :param serializer: An object model serializer.
    :param deserializer: An object model deserializer.
    :ivar api_version: The API version to be used with the HTTP request. Constant value: "2020-06-16".
    """

    models = models

    def __init__(self, client, config, serializer, deserializer):

        self._client = client
        self._serialize = serializer
        self._deserialize = deserializer
        self.api_version = config.api_version or "2020-06-16"

        self.config = config

    def get(
            self, resource_group_name, plan_name, custom_headers=None, raw=False, **operation_config):
        """Retrieves information about a Codespaces Plan resource.

        Retrieves the properties of a Codespaces Plan.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlan or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlan or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.get.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct and send request
        request = self._client.get(url, query_parameters, header_parameters)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlan', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}'}

    def delete(
            self, resource_group_name, plan_name, custom_headers=None, raw=False, **operation_config):
        """Deletes a Codespaces Plan resource.

        Deletes an existing Codespaces Plan.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: None or ClientRawResponse if raw=true
        :rtype: None or ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.delete.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

        # Construct headers
        header_parameters = {}
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct and send request
        request = self._client.delete(url, query_parameters, header_parameters)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200, 204]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        if raw:
            client_raw_response = ClientRawResponse(None, response)
            return client_raw_response
    delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}'}

    def create(
            self, resource_group_name, plan_name, codespaces_plan, custom_headers=None, raw=False, **operation_config):
        """Creates a Codespaces Plan.

        Creates a Codespaces Plan with the specified create parameters.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param codespaces_plan: Codespaces Plan create parameters.
        :type codespaces_plan: ~microsoft.codespaces.models.CodespacesPlan
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlan or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlan or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.create.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct body
        body_content = self._serialize.body(codespaces_plan, 'CodespacesPlan')

        # Construct and send request
        request = self._client.put(url, query_parameters, header_parameters, body_content)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlan', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    create.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}'}

    def update(
            self, resource_group_name, plan_name, codespaces_plan_update_parameters, custom_headers=None, raw=False, **operation_config):
        """Updates a Codespaces Plan.

        Updates the properties of an existing Codespaces Plan with the
        specified update parameters.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param codespaces_plan_update_parameters: Parameters for updating the
         Codespaces Plan.
        :type codespaces_plan_update_parameters:
         ~microsoft.codespaces.models.CodespacesPlanUpdateParameters
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlan or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlan or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.update.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct body
        body_content = self._serialize.body(codespaces_plan_update_parameters, 'CodespacesPlanUpdateParameters')

        # Construct and send request
        request = self._client.patch(url, query_parameters, header_parameters, body_content)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlan', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}'}

    def read_all_codespaces_action(
            self, resource_group_name, plan_name, expiration=None, custom_headers=None, raw=False, **operation_config):
        """Get Codespaces Plan read codespaces access token.

        Get Codespaces Plan access token which allows listing all codespaces in
        the Plan.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param expiration: The requested expiration of a Codespaces Plan
         access token.
        :type expiration: long
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlanAccessToken or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlanAccessToken or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.read_all_codespaces_action.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if expiration is not None:
            query_parameters['expiration'] = self._serialize.query("expiration", expiration, 'long')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct and send request
        request = self._client.post(url, query_parameters, header_parameters)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlanAccessToken', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    read_all_codespaces_action.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}/readAllCodespaces'}

    def write_codespaces_action(
            self, resource_group_name, plan_name, expiration=None, custom_headers=None, raw=False, **operation_config):
        """Get Codespaces Plan write codespaces access token.

        Get Codespaces Plan access token which allows creating, updating,
        deleting and connecting to codespaces owned by the user.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param expiration: The requested expiration of a Codespaces Plan
         access token.
        :type expiration: long
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlanAccessToken or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlanAccessToken or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.write_codespaces_action.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if expiration is not None:
            query_parameters['expiration'] = self._serialize.query("expiration", expiration, 'long')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct and send request
        request = self._client.post(url, query_parameters, header_parameters)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlanAccessToken', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    write_codespaces_action.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}/writeCodespaces'}

    def delete_all_codespaces_action(
            self, resource_group_name, plan_name, expiration=None, custom_headers=None, raw=False, **operation_config):
        """Get Codespaces Plan read and delete codespaces access token.

        Get Codespaces Plan access token which allows reading and deleting all
        codespaces in the Plan.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param expiration: The requested expiration of a Codespaces Plan
         access token.
        :type expiration: long
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlanAccessToken or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlanAccessToken or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.delete_all_codespaces_action.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
        if expiration is not None:
            query_parameters['expiration'] = self._serialize.query("expiration", expiration, 'long')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct and send request
        request = self._client.post(url, query_parameters, header_parameters)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlanAccessToken', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    delete_all_codespaces_action.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}/deleteAllCodespaces'}

    def write_delegates_action(
            self, resource_group_name, plan_name, delegate_request, custom_headers=None, raw=False, **operation_config):
        """Get Codespaces Plan delegated write codespaces access token.

        Get Codespaces Plan delegated access token which allows creating,
        updating, deleting and connecting to codespaces owned by the user.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param plan_name: Name of the Codespaces Plan
        :type plan_name: str
        :param delegate_request: Codespaces Plan delegate access token
         parameters.
        :type delegate_request:
         ~microsoft.codespaces.models.CodespacesDelegateAccessTokenRequestBody
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: CodespacesPlanAccessToken or ClientRawResponse if raw=true
        :rtype: ~microsoft.codespaces.models.CodespacesPlanAccessToken or
         ~msrest.pipeline.ClientRawResponse
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        # Construct URL
        url = self.write_delegates_action.metadata['url']
        path_format_arguments = {
            'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
            'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1),
            'planName': self._serialize.url("plan_name", plan_name, 'str', pattern=r'^[a-zA-Z0-9]')
        }
        url = self._client.format_url(url, **path_format_arguments)

        # Construct parameters
        query_parameters = {}
        query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

        # Construct headers
        header_parameters = {}
        header_parameters['Accept'] = 'application/json'
        header_parameters['Content-Type'] = 'application/json; charset=utf-8'
        if self.config.generate_client_request_id:
            header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
        if custom_headers:
            header_parameters.update(custom_headers)
        if self.config.accept_language is not None:
            header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

        # Construct body
        body_content = self._serialize.body(delegate_request, 'CodespacesDelegateAccessTokenRequestBody')

        # Construct and send request
        request = self._client.post(url, query_parameters, header_parameters, body_content)
        response = self._client.send(request, stream=False, **operation_config)

        if response.status_code not in [200]:
            raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

        deserialized = None

        if response.status_code == 200:
            deserialized = self._deserialize('CodespacesPlanAccessToken', response)

        if raw:
            client_raw_response = ClientRawResponse(deserialized, response)
            return client_raw_response

        return deserialized
    write_delegates_action.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans/{planName}/writeDelegates'}

    def list_by_resource_group(
            self, resource_group_name, custom_headers=None, raw=False, **operation_config):
        """Retrieves information about all Codespaces Plan resources under the
        given subscription and resource group.

        Retrieves the properties of all Codespaces Plans.

        :param resource_group_name: The name of the resource group.
        :type resource_group_name: str
        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: An iterator like instance of CodespacesPlan
        :rtype:
         ~microsoft.codespaces.models.CodespacesPlanPaged[~microsoft.codespaces.models.CodespacesPlan]
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        def internal_paging(next_link=None, raw=False):

            if not next_link:
                # Construct URL
                url = self.list_by_resource_group.metadata['url']
                path_format_arguments = {
                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'),
                    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1)
                }
                url = self._client.format_url(url, **path_format_arguments)

                # Construct parameters
                query_parameters = {}
                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

            else:
                url = next_link
                query_parameters = {}

            # Construct headers
            header_parameters = {}
            header_parameters['Accept'] = 'application/json'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters, header_parameters)
            response = self._client.send(request, stream=False, **operation_config)

            if response.status_code not in [200]:
                raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

            return response

        # Deserialize response
        deserialized = models.CodespacesPlanPaged(internal_paging, self._deserialize.dependencies)

        if raw:
            header_dict = {}
            client_raw_response = models.CodespacesPlanPaged(internal_paging, self._deserialize.dependencies, header_dict)
            return client_raw_response

        return deserialized
    list_by_resource_group.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Codespaces/plans'}

    def list_by_subscription(
            self, custom_headers=None, raw=False, **operation_config):
        """Retrieves information about all Codespaces Plan resources under the
        given subscription.

        Retrieves the properties of all Codespaces Plans.

        :param dict custom_headers: headers that will be added to the request
        :param bool raw: returns the direct response alongside the
         deserialized response
        :param operation_config: :ref:`Operation configuration
         overrides<msrest:optionsforoperations>`.
        :return: An iterator like instance of CodespacesPlan
        :rtype:
         ~microsoft.codespaces.models.CodespacesPlanPaged[~microsoft.codespaces.models.CodespacesPlan]
        :raises:
         :class:`CodespacesPlanErrorResponseException<microsoft.codespaces.models.CodespacesPlanErrorResponseException>`
        """
        def internal_paging(next_link=None, raw=False):

            if not next_link:
                # Construct URL
                url = self.list_by_subscription.metadata['url']
                path_format_arguments = {
                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
                }
                url = self._client.format_url(url, **path_format_arguments)

                # Construct parameters
                query_parameters = {}
                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

            else:
                url = next_link
                query_parameters = {}

            # Construct headers
            header_parameters = {}
            header_parameters['Accept'] = 'application/json'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters, header_parameters)
            response = self._client.send(request, stream=False, **operation_config)

            if response.status_code not in [200]:
                raise models.CodespacesPlanErrorResponseException(self._deserialize, response)

            return response

        # Deserialize response
        deserialized = models.CodespacesPlanPaged(internal_paging, self._deserialize.dependencies)

        if raw:
            header_dict = {}
            client_raw_response = models.CodespacesPlanPaged(internal_paging, self._deserialize.dependencies, header_dict)
            return client_raw_response

        return deserialized
    list_by_subscription.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Codespaces/plans'}
