# --------------------------------------------------------------------------
# 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.
# --------------------------------------------------------------------------

from knack.cli import CLIError


def validate_provider_resource_id(ns):
    resource_id = getattr(ns, 'identifier', None)
    if resource_id:
        if ns.resource_group_name or ns.provider_name:
            raise CLIError('Please omit --resource-group/-g or --name/-n if you have already specified --id.')

        ns.resource_group_name = resource_id.split('/')[4]
        ns.provider_name = resource_id.split('/')[8]

    if not all([ns.resource_group_name, ns.provider_name]):
        raise CLIError('Please specify both --resource-group/-g and --name/-n.')

    del ns.identifier
