# --------------------------------------------------------------------------
# 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 os
from azure.cli.testsdk import ScenarioTest
from .. import try_manual, raise_if, calc_coverage
from azure.cli.testsdk import ResourceGroupPreparer


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))


@try_manual
def setup(test, rg):
    pass


# EXAMPLE: /profiles/put/Create or update a Footprint profile.
@try_manual
def step__profiles_put_create_or_update_a_footprint_profile_(test, rg):
    test.cmd('az footprint profile create '
             '--location "westus2" '
             '--measurement-count 3 '
             '--start-delay-ms 5000 '
             '--tags key1="value1" key2="value2" '
             '--name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /profiles/get/Get the details of a Footprint profile.
@try_manual
def step__profiles_get_get_the_details_of_a_footprint_profile_(test, rg):
    test.cmd('az footprint profile show '
             '--name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /profiles/get/List all Footprint profiles under a Resource Group.
@try_manual
def step__profiles_get_list_all_footprint_profiles_under_a_resource_group_(test, rg):
    test.cmd('az footprint profile list '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /profiles/get/List all Footprint profiles under a subscription.
@try_manual
def step__profiles_get_list_all_footprint_profiles_under_a_subscription_(test, rg):
    test.cmd('az footprint profile list '
             '-g ""',
             checks=[])


# EXAMPLE: /profiles/patch/Update a Footprint profile.
@try_manual
def step__profiles_patch_update_a_footprint_profile_(test, rg):
    test.cmd('az footprint profile update '
             '--tags key1="value1" key2="value2" '
             '--name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /experiments/put/Create or update an experiment.
@try_manual
def step__experiments_put_create_or_update_an_experiment_(test, rg):
    test.cmd('az footprint experiment create '
             '--name "{myExperiment}" '
             '--description "An experiment description." '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /experiments/get/Get the details of an experiment.
@try_manual
def step__experiments_get_get_the_details_of_an_experiment_(test, rg):
    test.cmd('az footprint experiment show '
             '--name "{myExperiment}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /experiments/get/List all experiments under a Footprint profile.
@try_manual
def step__experiments_get_list_all_experiments_under_a_footprint_profile_(test, rg):
    test.cmd('az footprint experiment list '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpoints/put/Create or update a measurement endpoint.
@try_manual
def step__measurementendpoints_put_create_or_update_a_measurement_endpoint_(test, rg):
    test.cmd('az footprint measurement-endpoint create '
             '--name "{myMeasurementEndpoint}" '
             '--endpoint "www.contoso.com" '
             '--experiment-id "664cdec4f07d4e1083c9b3969ee2c49b" '
             '--measurement-type 2 '
             '--object-path "/trans.gif" '
             '--weight 10 '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpoints/get/Get the details of a measurement endpoint.
@try_manual
def step__measurementendpoints_get_get_the_details_of_a_measurement_endpoint_(test, rg):
    test.cmd('az footprint measurement-endpoint show '
             '--name "{myMeasurementEndpoint}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpoints/get/List all the measurement endpoints under a Footprint profile.
@try_manual
def step__measurementendpoints_get_list_all_the_measurement_endpoints_under_a_footprint_profile_(test, rg):
    test.cmd('az footprint measurement-endpoint list '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpointConditions/put/Create or update a measurement endpoint condition.
@try_manual
def step__measurementendpointconditions_put_create_or_update_a_measurement_endpoint_condition_(test, rg):
    test.cmd('az footprint measurement-endpoint-condition create '
             '--name "condition0" '
             '--endpoint-name "{myMeasurementEndpoint}" '
             '--constant "Edge-Prod-WST" '
             '--operator "MatchValueIgnoreCasing" '
             '--variable "X-FD-EdgeEnvironment" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpointConditions/get/Get the details of a measurement endpoint condition.
@try_manual
def step__measurementendpointconditions_get_get_the_details_of_a_measurement_endpoint_condition_(test, rg):
    test.cmd('az footprint measurement-endpoint-condition show '
             '--name "condition0" '
             '--endpoint-name "{myMeasurementEndpoint}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpointConditions/get/List all conditions under a measurement endpoint.
@try_manual
def step__measurementendpointconditions_get_list_all_conditions_under_a_measurement_endpoint_(test, rg):
    test.cmd('az footprint measurement-endpoint-condition list '
             '--endpoint-name "{myMeasurementEndpoint}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpointConditions/delete/Delete a measurement endpoint condition.
@try_manual
def step__measurementendpointconditions_delete_delete_a_measurement_endpoint_condition_(test, rg):
    test.cmd('az footprint measurement-endpoint-condition delete -y '
             '--name "condition0" '
             '--endpoint-name "{myMeasurementEndpoint}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /experiments/delete/Delete an experiment.
@try_manual
def step__experiments_delete_delete_an_experiment_(test, rg):
    test.cmd('az footprint experiment delete -y '
             '--name "{myExperiment}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /measurementEndpoints/delete/Delete a measurement endpoint.
@try_manual
def step__measurementendpoints_delete_delete_a_measurement_endpoint_(test, rg):
    test.cmd('az footprint measurement-endpoint delete -y '
             '--name "{myMeasurementEndpoint}" '
             '--profile-name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


# EXAMPLE: /profiles/delete/Delete a Footprint profile.
@try_manual
def step__profiles_delete_delete_a_footprint_profile_(test, rg):
    test.cmd('az footprint profile delete -y '
             '--name "{myProfile}" '
             '--resource-group "{rg}"',
             checks=[])


@try_manual
def cleanup(test, rg):
    pass


@try_manual
def call_scenario(test, rg):
    setup(test, rg)
    step__profiles_put_create_or_update_a_footprint_profile_(test, rg)
    step__profiles_get_get_the_details_of_a_footprint_profile_(test, rg)
    step__profiles_get_list_all_footprint_profiles_under_a_resource_group_(test, rg)
    step__profiles_get_list_all_footprint_profiles_under_a_subscription_(test, rg)
    step__profiles_patch_update_a_footprint_profile_(test, rg)
    step__experiments_put_create_or_update_an_experiment_(test, rg)
    step__experiments_get_get_the_details_of_an_experiment_(test, rg)
    step__experiments_get_list_all_experiments_under_a_footprint_profile_(test, rg)
    step__measurementendpoints_put_create_or_update_a_measurement_endpoint_(test, rg)
    step__measurementendpoints_get_get_the_details_of_a_measurement_endpoint_(test, rg)
    step__measurementendpoints_get_list_all_the_measurement_endpoints_under_a_footprint_profile_(test, rg)
    step__measurementendpointconditions_put_create_or_update_a_measurement_endpoint_condition_(test, rg)
    step__measurementendpointconditions_get_get_the_details_of_a_measurement_endpoint_condition_(test, rg)
    step__measurementendpointconditions_get_list_all_conditions_under_a_measurement_endpoint_(test, rg)
    step__measurementendpointconditions_delete_delete_a_measurement_endpoint_condition_(test, rg)
    step__experiments_delete_delete_an_experiment_(test, rg)
    step__measurementendpoints_delete_delete_a_measurement_endpoint_(test, rg)
    step__profiles_delete_delete_a_footprint_profile_(test, rg)
    cleanup(test, rg)


@try_manual
class FootprintMonitoringManagementClientScenarioTest(ScenarioTest):

    @ResourceGroupPreparer(name_prefix='clitestfootprint_rgName'[:7], key='rg', parameter_name='rg')
    def test_footprint(self, rg):

        self.kwargs.update({
            'myProfile': self.create_random_name(prefix='fpProfile1'[:5], length=10),
            'myMeasurementEndpoint': self.create_random_name(prefix='endpoint1'[:4], length=9),
            'myExperiment': self.create_random_name(prefix='fpExp1'[:2], length=9),
        })

        call_scenario(self, rg)
        calc_coverage(__file__)
        raise_if()
