# --------------------------------------------------------------------------
# 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 azure.cli.testsdk import ResourceGroupPreparer
from .example_steps import step_vmware_site_create
from .example_steps import step_vmware_site_show
from .example_steps import step_vmware_site_delete
from .example_steps import step_hyperv_site_create
from .example_steps import step_hyperv_site_show
from .example_steps import step_hyperv_cluster_show
from .example_steps import step_hyperv_cluster_list
from .example_steps import step_hyperv_host_show
from .example_steps import step_hyperv_host_list
from .example_steps import step_hyperv_site_delete
from .example_steps import step_vmware_machine_show
from .example_steps import step_vmware_machine_list
from .example_steps import step_hyperv_machine_show
from .example_steps import step_hyperv_machine_list
from .example_steps import step_hyperv_run_as_account_show
from .example_steps import step_hyperv_run_as_account_list
from .example_steps import step_vmware_run_as_account_show
from .example_steps import step_vmware_run_as_account_list
from .example_steps import step_vmware_vcenter_show
from .example_steps import step_vmware_vcenter_list
from .. import (
    try_manual,
    raise_if,
    calc_coverage
)


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


# Env setup_scenario
def setup_scenario(test, rg):
    pass


# Env cleanup_scenario
def cleanup_scenario(test, rg):
    pass


# Testcase: Scenario
def call_scenario(test, rg):
    setup_scenario(test, rg)

    # HyperV related tests
    step_hyperv_site_create(test, checks=[
        test.check("name", "{hyperv_site}")
    ])
    step_hyperv_site_show(test, checks=[
        test.check("name", "{hyperv_site}")
    ])
    step_hyperv_cluster_show(test)
    step_hyperv_cluster_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_hyperv_host_show(test)
    step_hyperv_host_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_hyperv_machine_show(test)
    step_hyperv_machine_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_hyperv_run_as_account_show(test)
    step_hyperv_run_as_account_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_hyperv_site_delete(test)

    # VMware related tests
    step_vmware_site_create(test, checks=[
        test.check("name", "{vmware_site}")
    ])
    step_vmware_site_show(test, checks=[
        test.check("name", "{vmware_site}")
    ])
    step_vmware_machine_show(test)
    step_vmware_machine_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_vmware_run_as_account_show(test)
    step_vmware_run_as_account_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_vmware_vcenter_show(test)
    step_vmware_vcenter_list(test, checks=[
        test.check("length(@)", 0)
    ])
    step_vmware_site_delete(test)

    cleanup_scenario(test, rg)


# Test class for Scenario
class OffazureScenarioTest(ScenarioTest):

    def __init__(self, *args, **kwargs):
        super(OffazureScenarioTest, self).__init__(*args, **kwargs)
        self.kwargs.update({
            'subscription_id': self.get_subscription_id()
        })

        self.kwargs.update({
            'hyperv_site': 'hyperv-site',
            'vmware_site': 'vmware-site',
        })

    @ResourceGroupPreparer(name_prefix='clitestoffazure_myResourceGroup'[:7], key='rg', parameter_name='rg')
    def test_offazure_Scenario(self, rg):
        call_scenario(self, rg)
        calc_coverage(__file__)
        raise_if()
