'''
Manage Azure IoT hubs.
'''
from ... pyaz_utils import _call_az
from . import certificate, consumer_group, devicestream, identity, message_enrichment, policy, route, routing_endpoint


def create(name, resource_group, c2d_max_delivery_count=None, c2d_ttl=None, disable_device_sas=None, disable_local_auth=None, disable_module_sas=None, feedback_lock_duration=None, feedback_max_delivery_count=None, feedback_ttl=None, fileupload_notification_lock_duration=None, fileupload_notification_max_delivery_count=None, fileupload_notification_ttl=None, fileupload_notifications=None, fileupload_sas_ttl=None, fileupload_storage_auth_type=None, fileupload_storage_connectionstring=None, fileupload_storage_container_name=None, fileupload_storage_container_uri=None, fileupload_storage_identity=None, location=None, mi_system_assigned=None, mi_user_assigned=None, min_tls_version=None, partition_count=None, retention_day=None, role=None, scopes=None, sku=None, tags=None, unit=None):
    '''
    Create an Azure IoT hub.

    Required Parameters:
    - name -- IoT Hub name.
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`

    Optional Parameters:
    - c2d_max_delivery_count -- The number of times the IoT hub will attempt to deliver a cloud-to-device message to a device, between 1 and 100.
    - c2d_ttl -- The amount of time a message is available for the device to consume before it is expired by IoT Hub, between 1 and 48 hours.
    - disable_device_sas -- A boolean indicating whether or not to disable all device (including Edge devices but excluding modules) scoped SAS keys for authentication
    - disable_local_auth -- A boolean indicating whether or not to disable IoT hub scoped SAS keys for authentication.
    - disable_module_sas -- A boolean indicating whether or not to disable module-scoped SAS keys for authentication.
    - feedback_lock_duration -- The lock duration for the feedback queue, between 5 and 300 seconds.
    - feedback_max_delivery_count -- The number of times the IoT hub attempts to deliver a message on the feedback queue, between 1 and 100.
    - feedback_ttl -- The period of time for which the IoT hub will maintain the feedback for expiration or delivery of cloud-to-device messages, between 1 and 48 hours.
    - fileupload_notification_lock_duration -- The lock duration for the file upload notifications queue, between 5 and 300 seconds.
    - fileupload_notification_max_delivery_count -- The number of times the IoT hub will attempt to deliver a file notification message, between 1 and 100.
    - fileupload_notification_ttl -- The amount of time a file upload notification is available for the service to consume before it is expired by IoT Hub, between 1 and 48 hours.
    - fileupload_notifications -- A boolean indicating whether to log information about uploaded files to the messages/servicebound/filenotifications IoT Hub endpoint.
    - fileupload_sas_ttl -- The amount of time a SAS URI generated by IoT Hub is valid before it expires, between 1 and 24 hours.
    - fileupload_storage_auth_type -- The authentication type for the Azure Storage account to which files are uploaded.
    - fileupload_storage_connectionstring -- The connection string for the Azure Storage account to which files are uploaded.
    - fileupload_storage_container_name -- The name of the root container where you upload files. The container need not exist but should be creatable using the connectionString specified.
    - fileupload_storage_container_uri -- The container URI for the Azure Storage account to which files are uploaded.
    - fileupload_storage_identity -- The managed identity to use for file upload authentication. Use '[system]' to refer to the system-assigned managed identity or a resource ID to refer to a user-assigned managed identity.
    - location -- Location of your IoT Hub. Default is the location of target resource group.
    - mi_system_assigned -- Enable system-assigned managed identity for this hub
    - mi_user_assigned -- Enable user-assigned managed identities for this hub. Accept space-separated list of identity resource IDs.
    - min_tls_version -- Specify the minimum TLS version to support for this hub. Can be set to "1.2" to have clients that use a TLS version below 1.2 to be rejected.
    - partition_count -- The number of partitions of the backing Event Hub for device-to-cloud messages.
    - retention_day -- Specifies how long this IoT hub will maintain device-to-cloud events, between 1 and 7 days.
    - role -- Role to assign to the hub's system-assigned managed identity.
    - scopes -- Space separated list of scopes to assign the role (--role) for the system-assigned managed identity.
    - sku -- Pricing tier for Azure IoT Hub. Note that only one free IoT hub instance (F1) is allowed in each subscription. Exception will be thrown if free instances exceed one.
    - tags -- space-separated tags: key[=value] [key[=value] ...]. Use '' to clear existing tags.
    - unit -- Units in your IoT Hub.
    '''
    return _call_az("az iot hub create", locals())


def list(resource_group=None):
    '''
    List IoT hubs.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub list", locals())


def show_connection_string(all=None, hub_name=None, key=None, policy_name=None, resource_group=None):
    '''
    Show the connection strings for an IoT hub.

    Optional Parameters:
    - all -- Allow to show all shared access policies.
    - hub_name -- IoT Hub name.
    - key -- The key to use.
    - policy_name -- Shared access policy to use.
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub show-connection-string", locals())


def show(name, resource_group=None):
    '''
    Get the details of an IoT hub.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub show", locals())


def update(name, add=None, c2d_max_delivery_count=None, c2d_ttl=None, disable_device_sas=None, disable_local_auth=None, disable_module_sas=None, feedback_lock_duration=None, feedback_max_delivery_count=None, feedback_ttl=None, fileupload_notification_lock_duration=None, fileupload_notification_max_delivery_count=None, fileupload_notification_ttl=None, fileupload_notifications=None, fileupload_sas_ttl=None, fileupload_storage_auth_type=None, fileupload_storage_connectionstring=None, fileupload_storage_container_name=None, fileupload_storage_container_uri=None, fileupload_storage_identity=None, force_string=None, remove=None, resource_group=None, retention_day=None, set=None, sku=None, tags=None, unit=None):
    '''
    Update metadata for an IoT hub.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - add -- Add an object to a list of objects by specifying a path and key value pairs.  Example: --add property.listProperty <key=value, string or JSON string>
    - c2d_max_delivery_count -- The number of times the IoT hub will attempt to deliver a cloud-to-device message to a device, between 1 and 100.
    - c2d_ttl -- The amount of time a message is available for the device to consume before it is expired by IoT Hub, between 1 and 48 hours.
    - disable_device_sas -- A boolean indicating whether or not to disable all device (including Edge devices but excluding modules) scoped SAS keys for authentication
    - disable_local_auth -- A boolean indicating whether or not to disable IoT hub scoped SAS keys for authentication.
    - disable_module_sas -- A boolean indicating whether or not to disable module-scoped SAS keys for authentication.
    - feedback_lock_duration -- The lock duration for the feedback queue, between 5 and 300 seconds.
    - feedback_max_delivery_count -- The number of times the IoT hub attempts to deliver a message on the feedback queue, between 1 and 100.
    - feedback_ttl -- The period of time for which the IoT hub will maintain the feedback for expiration or delivery of cloud-to-device messages, between 1 and 48 hours.
    - fileupload_notification_lock_duration -- The lock duration for the file upload notifications queue, between 5 and 300 seconds.
    - fileupload_notification_max_delivery_count -- The number of times the IoT hub will attempt to deliver a file notification message, between 1 and 100.
    - fileupload_notification_ttl -- The amount of time a file upload notification is available for the service to consume before it is expired by IoT Hub, between 1 and 48 hours.
    - fileupload_notifications -- A boolean indicating whether to log information about uploaded files to the messages/servicebound/filenotifications IoT Hub endpoint.
    - fileupload_sas_ttl -- The amount of time a SAS URI generated by IoT Hub is valid before it expires, between 1 and 24 hours.
    - fileupload_storage_auth_type -- The authentication type for the Azure Storage account to which files are uploaded.
    - fileupload_storage_connectionstring -- The connection string for the Azure Storage account to which files are uploaded.
    - fileupload_storage_container_name -- The name of the root container where you upload files. The container need not exist but should be creatable using the connectionString specified.
    - fileupload_storage_container_uri -- The container URI for the Azure Storage account to which files are uploaded.
    - fileupload_storage_identity -- The managed identity to use for file upload authentication. Use '[system]' to refer to the system-assigned managed identity or a resource ID to refer to a user-assigned managed identity.
    - force_string -- When using 'set' or 'add', preserve string literals instead of attempting to convert to JSON.
    - remove -- Remove a property or an element from a list.  Example: --remove property.list <indexToRemove> OR --remove propertyToRemove
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    - retention_day -- Specifies how long this IoT hub will maintain device-to-cloud events, between 1 and 7 days.
    - set -- Update an object by specifying a property path and value to set.  Example: --set property1.property2=<value>
    - sku -- Pricing tier for Azure IoT Hub. Note that only one free IoT hub instance (F1) is allowed in each subscription. Exception will be thrown if free instances exceed one.
    - tags -- space-separated tags: key[=value] [key[=value] ...]. Use '' to clear existing tags.
    - unit -- Units in your IoT Hub.
    '''
    return _call_az("az iot hub update", locals())


def delete(name, resource_group=None):
    '''
    Delete an IoT hub.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub delete", locals())


def list_skus(name, resource_group=None):
    '''
    List available pricing tiers.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub list-skus", locals())


def show_quota_metrics(name, resource_group=None):
    '''
    Get the quota metrics for an IoT hub.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub show-quota-metrics", locals())


def show_stats(name, resource_group=None):
    '''
    Get the statistics for an IoT hub.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub show-stats", locals())


def manual_failover(name, no_wait=None, resource_group=None):
    '''
    Initiate a manual failover for the IoT Hub to the geo-paired disaster recovery region.

    Required Parameters:
    - name -- IoT Hub name.

    Optional Parameters:
    - no_wait -- Do not wait for the long-running operation to finish.
    - resource_group -- Name of resource group. You can configure the default group using `az configure --defaults group=<name>`
    '''
    return _call_az("az iot hub manual-failover", locals())

