# --------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------
# pylint: disable=too-many-lines

from knack.util import CLIError
from azure.cli.core.util import sdk_no_wait


def quota_usage_list(client,
                     scope):
    return client.list(scope=scope)


def quota_usage_show(client,
                     resource_name,
                     scope):
    return client.get(resource_name=resource_name,
                      scope=scope)


def quota_list(client,
               scope):
    return client.list(scope=scope)


def quota_show(client,
               resource_name,
               scope):
    return client.get(resource_name=resource_name,
                      scope=scope)


def quota_create(client,
                 resource_name,
                 scope,
                 limit_object=None,
                 resource_type=None,
                 properties=None,
                 no_wait=False):
    all_limit = []
    if limit_object is not None:
        all_limit.append(limit_object)
    if len(all_limit) > 1:
        raise CLIError('at most one of  limit object is needed for limit!')
    limit = all_limit[0] if len(all_limit) == 1 else None
    create_quota_request = {}
    create_quota_request['properties'] = {}
    create_quota_request['properties']['limit'] = {}
    if limit is not None:
        create_quota_request['properties']['limit'] = limit
    if properties is not None:
        create_quota_request['properties']['properties'] = properties
    create_quota_request['properties']['name'] = {}
    if resource_name is not None:
        create_quota_request['properties']['name']['value'] = resource_name
    if len(create_quota_request['properties']['name']) == 0:
        del create_quota_request['properties']['name']
    if resource_type is not None:
        create_quota_request['properties']['resource_type'] = resource_type
    return sdk_no_wait(no_wait,
                       client.begin_create_or_update,
                       resource_name=resource_name,
                       scope=scope,
                       create_quota_request=create_quota_request)


def quota_update(client,
                 resource_name,
                 scope,
                 limit_object=None,
                 resource_type=None,
                 properties=None,
                 no_wait=False):
    all_limit = []
    if limit_object is not None:
        all_limit.append(limit_object)
    if len(all_limit) > 1:
        raise CLIError('at most one of  limit object is needed for limit!')
    limit = all_limit[0] if len(all_limit) == 1 else None
    create_quota_request = {}
    create_quota_request['properties'] = {}
    create_quota_request['properties']['limit'] = {}
    if limit is not None:
        create_quota_request['properties']['limit'] = limit
    if properties is not None:
        create_quota_request['properties']['properties'] = properties
    create_quota_request['properties']['name'] = {}
    if resource_name is not None:
        create_quota_request['properties']['name']['value'] = resource_name
    if len(create_quota_request['properties']['name']) == 0:
        del create_quota_request['properties']['name']
    if resource_type is not None:
        create_quota_request['properties']['resource_type'] = resource_type
    return sdk_no_wait(no_wait,
                       client.begin_update,
                       resource_name=resource_name,
                       scope=scope,
                       create_quota_request=create_quota_request)


def quota_request_status_list(client,
                              scope,
                              filter=None,
                              top=None,
                              skip_token=None):
    return client.list(scope=scope,
                       filter=filter,
                       top=top,
                       skiptoken=skip_token)


def quota_request_status_show(client,
                              name,
                              scope):
    return client.get(id=name,
                      scope=scope)


def quota_operation_list(client):
    return client.list()
