# --------------------------------------------------------------------------
# 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=line-too-long
# pylint: disable=too-many-lines
# pylint: disable=unused-argument

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


def datafactory_list(client,
                     resource_group_name=None,
                     gen_custom_headers=None):
    if resource_group_name:
        return client.list_by_resource_group(resource_group_name=resource_group_name)
    return client.list(custom_headers=gen_custom_headers)


def datafactory_show(client,
                     resource_group_name,
                     factory_name,
                     if_none_match=None):
    return client.get(resource_group_name=resource_group_name,
                      factory_name=factory_name,
                      if_none_match=if_none_match)


def datafactory_create(client,
                       resource_group_name,
                       factory_name,
                       if_match=None,
                       location=None,
                       tags=None,
                       test_inherit=None,
                       factory_vsts_configuration=None,
                       factory_git_hub_configuration=None,
                       fake_identity=None,
                       zones=None):
    all_repo_configuration = []
    if factory_vsts_configuration is not None:
        all_repo_configuration.append(factory_vsts_configuration)
    if factory_git_hub_configuration is not None:
        all_repo_configuration.append(factory_git_hub_configuration)
    if len(all_repo_configuration) > 1:
        raise CLIError('at most one of  factory_vsts_configuration, factory_git_hub_configuration is needed for '
                       'repo_configuration!')
    repo_configuration = all_repo_configuration[0] if len(all_repo_configuration) == 1 else None
    factory = {}
    if location is not None:
        factory['location'] = location
    if tags is not None:
        factory['tags'] = tags
    if test_inherit is not None:
        factory['test_inherit'] = test_inherit
    if repo_configuration is not None:
        factory['repo_configuration'] = repo_configuration
    if fake_identity is not None:
        factory['fake_identity'] = fake_identity
    if zones is not None:
        factory['zones'] = zones
    factory['identity'] = {}
    factory['identity']['type'] = "SystemAssigned"
    if len(factory['identity']) == 0:
        del factory['identity']
    return client.create_or_update(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   if_match=if_match,
                                   factory=factory)


def datafactory_update(client,
                       resource_group_name,
                       factory_name,
                       tags=None):
    factory_update_parameters = {}
    if tags is not None:
        factory_update_parameters['tags'] = tags
    factory_update_parameters['identity'] = {}
    factory_update_parameters['identity']['type'] = "SystemAssigned"
    if len(factory_update_parameters['identity']) == 0:
        del factory_update_parameters['identity']
    return client.update(resource_group_name=resource_group_name,
                         factory_name=factory_name,
                         factory_update_parameters=factory_update_parameters)


def datafactory_delete(client,
                       resource_group_name,
                       factory_name):
    return client.delete(resource_group_name=resource_group_name,
                         factory_name=factory_name)


def datafactory_configure_factory_repo(client,
                                       location_id,
                                       factory_resource_id=None,
                                       factory_vsts_configuration=None,
                                       factory_git_hub_configuration=None):
    all_repo_configuration = []
    if factory_vsts_configuration is not None:
        all_repo_configuration.append(factory_vsts_configuration)
    if factory_git_hub_configuration is not None:
        all_repo_configuration.append(factory_git_hub_configuration)
    if len(all_repo_configuration) > 1:
        raise CLIError('at most one of  factory_vsts_configuration, factory_git_hub_configuration is needed for '
                       'repo_configuration!')
    repo_configuration = all_repo_configuration[0] if len(all_repo_configuration) == 1 else None
    factory_repo_update = {}
    if factory_resource_id is not None:
        factory_repo_update['factory_resource_id'] = factory_resource_id
    if repo_configuration is not None:
        factory_repo_update['repo_configuration'] = repo_configuration
    return client.configure_factory_repo(location_id=location_id,
                                         factory_repo_update=factory_repo_update)


def datafactory_get_data_plane_access(client,
                                      resource_group_name,
                                      factory_name,
                                      permissions=None,
                                      access_resource_path=None,
                                      profile_name=None,
                                      start_time=None,
                                      expire_time=None):
    policy = {}
    if permissions is not None:
        policy['permissions'] = permissions
    if access_resource_path is not None:
        policy['access_resource_path'] = access_resource_path
    if profile_name is not None:
        policy['profile_name'] = profile_name
    if start_time is not None:
        policy['start_time'] = start_time
    if expire_time is not None:
        policy['expire_time'] = expire_time
    return client.get_data_plane_access(resource_group_name=resource_group_name,
                                        factory_name=factory_name,
                                        policy=policy)


def datafactory_get_git_hub_access_token(client,
                                         resource_group_name,
                                         factory_name,
                                         git_hub_access_code,
                                         git_hub_access_token_base_url,
                                         git_hub_client_id=None):
    git_hub_access_token_request = {}
    git_hub_access_token_request['git_hub_access_code'] = git_hub_access_code
    if git_hub_client_id is not None:
        git_hub_access_token_request['git_hub_client_id'] = git_hub_client_id
    git_hub_access_token_request['git_hub_access_token_base_url'] = git_hub_access_token_base_url
    return client.get_git_hub_access_token(resource_group_name=resource_group_name,
                                           factory_name=factory_name,
                                           git_hub_access_token_request=git_hub_access_token_request)


def datafactory_trigger_list(client,
                             resource_group_name,
                             factory_name):
    return client.list_by_factory(resource_group_name=resource_group_name,
                                  factory_name=factory_name)


def datafactory_trigger_show(client,
                             resource_group_name,
                             factory_name,
                             trigger_name,
                             if_none_match=None):
    return client.get(resource_group_name=resource_group_name,
                      factory_name=factory_name,
                      trigger_name=trigger_name,
                      if_none_match=if_none_match)


def datafactory_trigger_create(client,
                               resource_group_name,
                               factory_name,
                               trigger_name,
                               properties,
                               if_match=None):
    trigger = {}
    trigger['properties'] = properties
    return client.create_or_update(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   trigger_name=trigger_name,
                                   if_match=if_match,
                                   trigger=trigger)


def datafactory_trigger_update(instance,
                               resource_group_name,
                               factory_name,
                               trigger_name,
                               if_match=None,
                               description=None,
                               annotations=None):
    if description is not None:
        instance.properties.description = description
    if annotations is not None:
        instance.properties.annotations = annotations
    return instance


def datafactory_trigger_delete(client,
                               resource_group_name,
                               factory_name,
                               trigger_name):
    return client.delete(resource_group_name=resource_group_name,
                         factory_name=factory_name,
                         trigger_name=trigger_name)


def datafactory_trigger_get_event_subscription_status(client,
                                                      resource_group_name,
                                                      factory_name,
                                                      trigger_name):
    return client.get_event_subscription_status(resource_group_name=resource_group_name,
                                                factory_name=factory_name,
                                                trigger_name=trigger_name)


def datafactory_trigger_query_by_factory(client,
                                         resource_group_name,
                                         factory_name,
                                         continuation_token=None,
                                         parent_trigger_name=None):
    filter_parameters = {}
    if continuation_token is not None:
        filter_parameters['continuation_token'] = continuation_token
    if parent_trigger_name is not None:
        filter_parameters['parent_trigger_name'] = parent_trigger_name
    return client.query_by_factory(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   filter_parameters=filter_parameters)


def datafactory_trigger_start(client,
                              resource_group_name,
                              factory_name,
                              trigger_name,
                              no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_start,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       trigger_name=trigger_name)


def datafactory_trigger_stop(client,
                             resource_group_name,
                             factory_name,
                             trigger_name,
                             no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_stop,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       trigger_name=trigger_name)


def datafactory_trigger_subscribe_to_event(client,
                                           resource_group_name,
                                           factory_name,
                                           trigger_name,
                                           no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_subscribe_to_events,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       trigger_name=trigger_name)


def datafactory_trigger_unsubscribe_from_event(client,
                                               resource_group_name,
                                               factory_name,
                                               trigger_name,
                                               no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_unsubscribe_from_events,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       trigger_name=trigger_name)


def datafactory_integration_runtime_list(client,
                                         resource_group_name,
                                         factory_name):
    return client.list_by_factory(resource_group_name=resource_group_name,
                                  factory_name=factory_name)


def datafactory_integration_runtime_show(client,
                                         resource_group_name,
                                         factory_name,
                                         integration_runtime_name,
                                         if_none_match=None):
    return client.get(resource_group_name=resource_group_name,
                      factory_name=factory_name,
                      integration_runtime_name=integration_runtime_name,
                      if_none_match=if_none_match)


def datafactory_integration_runtime_managed_create(client,
                                                   resource_group_name,
                                                   factory_name,
                                                   integration_runtime_name,
                                                   if_match=None,
                                                   description=None,
                                                   factory_vsts_configuration=None,
                                                   factory_git_hub_configuration=None,
                                                   fake_identity=None,
                                                   zones=None,
                                                   compute_properties=None,
                                                   ssis_properties=None):
    all_repo_configuration = []
    if factory_vsts_configuration is not None:
        all_repo_configuration.append(factory_vsts_configuration)
    if factory_git_hub_configuration is not None:
        all_repo_configuration.append(factory_git_hub_configuration)
    if len(all_repo_configuration) > 1:
        raise CLIError('at most one of  factory_vsts_configuration, factory_git_hub_configuration is needed for '
                       'repo_configuration!')
    repo_configuration = all_repo_configuration[0] if len(all_repo_configuration) == 1 else None
    integration_runtime = {}
    integration_runtime['properties'] = {}
    integration_runtime['properties']['type'] = 'Managed'
    if description is not None:
        integration_runtime['properties']['description'] = description
    if repo_configuration is not None:
        integration_runtime['properties']['repo_configuration'] = repo_configuration
    if fake_identity is not None:
        integration_runtime['properties']['fake_identity'] = fake_identity
    if zones is not None:
        integration_runtime['properties']['zones'] = zones
    if compute_properties is not None:
        integration_runtime['properties']['compute_properties'] = compute_properties
    if ssis_properties is not None:
        integration_runtime['properties']['ssis_properties'] = ssis_properties
    return client.create_or_update(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   integration_runtime_name=integration_runtime_name,
                                   if_match=if_match,
                                   integration_runtime=integration_runtime)


def datafactory_integration_runtime_self_hosted_create(client,
                                                       resource_group_name,
                                                       factory_name,
                                                       integration_runtime_name,
                                                       if_match=None,
                                                       description=None,
                                                       linked_info=None):
    integration_runtime = {}
    integration_runtime['properties'] = {}
    integration_runtime['properties']['type'] = 'SelfHosted'
    if description is not None:
        integration_runtime['properties']['description'] = description
    if linked_info is not None:
        integration_runtime['properties']['linked_info'] = linked_info
    return client.create_or_update(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   integration_runtime_name=integration_runtime_name,
                                   if_match=if_match,
                                   integration_runtime=integration_runtime)


def datafactory_integration_runtime_update(client,
                                           resource_group_name,
                                           factory_name,
                                           integration_runtime_name,
                                           auto_update=None,
                                           update_delay_offset=None):
    update_integration_runtime_request = {}
    if auto_update is not None:
        update_integration_runtime_request['auto_update'] = auto_update
    if update_delay_offset is not None:
        update_integration_runtime_request['update_delay_offset'] = update_delay_offset
    return client.update(resource_group_name=resource_group_name,
                         factory_name=factory_name,
                         integration_runtime_name=integration_runtime_name,
                         update_integration_runtime_request=update_integration_runtime_request)


def datafactory_integration_runtime_delete(client,
                                           resource_group_name,
                                           factory_name,
                                           integration_runtime_name):
    return client.delete(resource_group_name=resource_group_name,
                         factory_name=factory_name,
                         integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_get_connection_info(client,
                                                        resource_group_name,
                                                        factory_name,
                                                        integration_runtime_name):
    return client.get_connection_info(resource_group_name=resource_group_name,
                                      factory_name=factory_name,
                                      integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_get_monitoring_data(client,
                                                        resource_group_name,
                                                        factory_name,
                                                        integration_runtime_name):
    return client.get_monitoring_data(resource_group_name=resource_group_name,
                                      factory_name=factory_name,
                                      integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_get_status(client,
                                               resource_group_name,
                                               factory_name,
                                               integration_runtime_name):
    return client.get_status(resource_group_name=resource_group_name,
                             factory_name=factory_name,
                             integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_list_auth_key(client,
                                                  resource_group_name,
                                                  factory_name,
                                                  integration_runtime_name):
    return client.list_auth_keys(resource_group_name=resource_group_name,
                                 factory_name=factory_name,
                                 integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_regenerate_auth_key(client,
                                                        resource_group_name,
                                                        factory_name,
                                                        integration_runtime_name,
                                                        key_name=None):
    regenerate_key_parameters = {}
    if key_name is not None:
        regenerate_key_parameters['key_name'] = key_name
    return client.regenerate_auth_key(resource_group_name=resource_group_name,
                                      factory_name=factory_name,
                                      integration_runtime_name=integration_runtime_name,
                                      regenerate_key_parameters=regenerate_key_parameters)


def datafactory_integration_runtime_remove_link(client,
                                                resource_group_name,
                                                factory_name,
                                                integration_runtime_name,
                                                linked_factory_name):
    linked_integration_runtime_request = {}
    linked_integration_runtime_request['linked_factory_name'] = linked_factory_name
    return client.remove_links(resource_group_name=resource_group_name,
                               factory_name=factory_name,
                               integration_runtime_name=integration_runtime_name,
                               linked_integration_runtime_request=linked_integration_runtime_request)


def datafactory_integration_runtime_start(client,
                                          resource_group_name,
                                          factory_name,
                                          integration_runtime_name,
                                          no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_start,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_stop(client,
                                         resource_group_name,
                                         factory_name,
                                         integration_runtime_name,
                                         no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_stop,
                       resource_group_name=resource_group_name,
                       factory_name=factory_name,
                       integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_sync_credentials(client,
                                                     resource_group_name,
                                                     factory_name,
                                                     integration_runtime_name):
    return client.sync_credentials(resource_group_name=resource_group_name,
                                   factory_name=factory_name,
                                   integration_runtime_name=integration_runtime_name)


def datafactory_integration_runtime_upgrade(client,
                                            resource_group_name,
                                            factory_name,
                                            integration_runtime_name):
    return client.upgrade(resource_group_name=resource_group_name,
                          factory_name=factory_name,
                          integration_runtime_name=integration_runtime_name)


def datafactory_linked_integration_runtime_create(client,
                                                  resource_group_name,
                                                  factory_name,
                                                  integration_runtime_name,
                                                  name=None,
                                                  subscription_id=None,
                                                  data_factory_name=None,
                                                  data_factory_location=None):
    create_linked_integration_runtime_request = {}
    if name is not None:
        create_linked_integration_runtime_request['name'] = name
    if subscription_id is not None:
        create_linked_integration_runtime_request['subscription_id'] = subscription_id
    if data_factory_name is not None:
        create_linked_integration_runtime_request['data_factory_name'] = data_factory_name
    if data_factory_location is not None:
        create_linked_integration_runtime_request['data_factory_location'] = data_factory_location
    return client.create_linked_integration_runtime(resource_group_name=resource_group_name,
                                                    factory_name=factory_name,
                                                    integration_runtime_name=integration_runtime_name,
                                                    create_linked_integration_runtime_request=create_linked_integration_runtime_request)


def datafactory_domain_service_create(client,
                                      resource_group_name,
                                      domain_service_name,
                                      location=None,
                                      tags=None,
                                      domain_name=None,
                                      replica_sets=None,
                                      domain_configuration_type=None,
                                      sku=None,
                                      filtered_sync=None):
    domain_service = {}
    if location is not None:
        domain_service['location'] = location
    if tags is not None:
        domain_service['tags'] = tags
    if domain_name is not None:
        domain_service['domain_name'] = domain_name
    if replica_sets is not None:
        domain_service['replica_sets'] = replica_sets
    if domain_configuration_type is not None:
        domain_service['domain_configuration_type'] = domain_configuration_type
    if sku is not None:
        domain_service['sku'] = sku
    if filtered_sync is not None:
        domain_service['filtered_sync'] = filtered_sync
    return client.begin_create_or_update(resource_group_name=resource_group_name,
                                         domain_service_name=domain_service_name,
                                         domain_service=domain_service)


def datafactory_domain_service_update(client,
                                      resource_group_name,
                                      domain_service_name,
                                      location=None,
                                      tags=None,
                                      domain_name=None,
                                      replica_sets=None,
                                      domain_configuration_type=None,
                                      sku=None,
                                      filtered_sync=None):
    domain_service = {}
    if location is not None:
        domain_service['location'] = location
    if tags is not None:
        domain_service['tags'] = tags
    if domain_name is not None:
        domain_service['domain_name'] = domain_name
    if replica_sets is not None:
        domain_service['replica_sets'] = replica_sets
    if domain_configuration_type is not None:
        domain_service['domain_configuration_type'] = domain_configuration_type
    if sku is not None:
        domain_service['sku'] = sku
    if filtered_sync is not None:
        domain_service['filtered_sync'] = filtered_sync
    return client.begin_create_or_update(resource_group_name=resource_group_name,
                                         domain_service_name=domain_service_name,
                                         domain_service=domain_service)


def datafactory_group_create(client,
                             resource_group_name,
                             project_name,
                             group_name,
                             e_tag=None):
    group = {}
    if e_tag is not None:
        group['e_tag'] = e_tag
    group['properties'] = {}
    return client.create(resource_group_name=resource_group_name,
                         project_name=project_name,
                         group_name=group_name,
                         group=group)
