# --------------------------------------------------------------------------
# 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=too-many-lines

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


def datashare_account_list(client,
                           resource_group_name=None,
                           skip_token=None):
    if resource_group_name:
        return client.list_by_resource_group(resource_group_name=resource_group_name,
                                             skip_token=skip_token)
    return client.list_by_subscription(skip_token=skip_token)


def datashare_account_show(client,
                           resource_group_name,
                           account_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name)


def datashare_account_create(client,
                             resource_group_name,
                             account_name,
                             location=None,
                             tags=None,
                             no_wait=False):
    account = {}
    if location is not None:
        account['location'] = location
    if tags is not None:
        account['tags'] = tags
    account['identity'] = {}
    account['identity']['type'] = "SystemAssigned"
    if len(account['identity']) == 0:
        del account['identity']
    return sdk_no_wait(no_wait,
                       client.begin_create,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       account=account)


def datashare_account_update(client,
                             resource_group_name,
                             account_name,
                             tags=None):
    account_update_parameters = {}
    if tags is not None:
        account_update_parameters['tags'] = tags
    return client.update(resource_group_name=resource_group_name,
                         account_name=account_name,
                         account_update_parameters=account_update_parameters)


def datashare_account_delete(client,
                             resource_group_name,
                             account_name,
                             no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name)


def datashare_consumer_invitation_show(client,
                                       location,
                                       invitation_id):
    return client.get(location=location,
                      invitation_id=invitation_id)


def datashare_consumer_invitation_list_invitation(client,
                                                  skip_token=None):
    return client.list_invitations(skip_token=skip_token)


def datashare_consumer_invitation_reject_invitation(client,
                                                    location,
                                                    invitation_id):
    invitation = {}
    invitation['invitation_id'] = invitation_id
    return client.reject_invitation(location=location,
                                    invitation=invitation)


def datashare_data_set_list(client,
                            resource_group_name,
                            account_name,
                            share_name,
                            skip_token=None,
                            filter_=None,
                            orderby=None):
    return client.list_by_share(resource_group_name=resource_group_name,
                                account_name=account_name,
                                share_name=share_name,
                                skip_token=skip_token,
                                filter=filter_,
                                orderby=orderby)


def datashare_data_set_show(client,
                            resource_group_name,
                            account_name,
                            share_name,
                            data_set_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_name=share_name,
                      data_set_name=data_set_name)


def datashare_data_set_create(client,
                              resource_group_name,
                              account_name,
                              share_name,
                              data_set_name,
                              data_set):
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         data_set_name=data_set_name,
                         data_set=data_set)


def datashare_data_set_delete(client,
                              resource_group_name,
                              account_name,
                              share_name,
                              data_set_name,
                              no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_name=share_name,
                       data_set_name=data_set_name)


def datashare_data_set_mapping_list(client,
                                    resource_group_name,
                                    account_name,
                                    share_subscription_name,
                                    skip_token=None,
                                    filter_=None,
                                    orderby=None):
    return client.list_by_share_subscription(resource_group_name=resource_group_name,
                                             account_name=account_name,
                                             share_subscription_name=share_subscription_name,
                                             skip_token=skip_token,
                                             filter=filter_,
                                             orderby=orderby)


def datashare_data_set_mapping_show(client,
                                    resource_group_name,
                                    account_name,
                                    share_subscription_name,
                                    data_set_mapping_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_subscription_name=share_subscription_name,
                      data_set_mapping_name=data_set_mapping_name)


def datashare_data_set_mapping_create(client,
                                      resource_group_name,
                                      account_name,
                                      share_subscription_name,
                                      data_set_mapping_name,
                                      adls_gen2_file_data_set_mapping=None,
                                      adls_gen2_file_system_data_set_mapping=None,
                                      adls_gen2_folder_data_set_mapping=None,
                                      blob_container_data_set_mapping=None,
                                      blob_data_set_mapping=None,
                                      blob_folder_data_set_mapping=None,
                                      kusto_cluster_data_set_mapping=None,
                                      kusto_database_data_set_mapping=None,
                                      kusto_table_data_set_mapping=None,
                                      sqldb_table_data_set_mapping=None,
                                      sqldw_table_data_set_mapping=None,
                                      synapse_workspace_sql_pool_table_data_set_mapping=None):
    all_data_set_mapping = []
    if adls_gen2_file_data_set_mapping is not None:
        all_data_set_mapping.append(adls_gen2_file_data_set_mapping)
    if adls_gen2_file_system_data_set_mapping is not None:
        all_data_set_mapping.append(adls_gen2_file_system_data_set_mapping)
    if adls_gen2_folder_data_set_mapping is not None:
        all_data_set_mapping.append(adls_gen2_folder_data_set_mapping)
    if blob_container_data_set_mapping is not None:
        all_data_set_mapping.append(blob_container_data_set_mapping)
    if blob_data_set_mapping is not None:
        all_data_set_mapping.append(blob_data_set_mapping)
    if blob_folder_data_set_mapping is not None:
        all_data_set_mapping.append(blob_folder_data_set_mapping)
    if kusto_cluster_data_set_mapping is not None:
        all_data_set_mapping.append(kusto_cluster_data_set_mapping)
    if kusto_database_data_set_mapping is not None:
        all_data_set_mapping.append(kusto_database_data_set_mapping)
    if kusto_table_data_set_mapping is not None:
        all_data_set_mapping.append(kusto_table_data_set_mapping)
    if sqldb_table_data_set_mapping is not None:
        all_data_set_mapping.append(sqldb_table_data_set_mapping)
    if sqldw_table_data_set_mapping is not None:
        all_data_set_mapping.append(sqldw_table_data_set_mapping)
    if synapse_workspace_sql_pool_table_data_set_mapping is not None:
        all_data_set_mapping.append(synapse_workspace_sql_pool_table_data_set_mapping)
    if len(all_data_set_mapping) > 1:
        raise CLIError('at most one of  adls_gen2_file_data_set_mapping, adls_gen2_file_system_data_set_mapping, '
                       'adls_gen2_folder_data_set_mapping, blob_container_data_set_mapping, blob_data_set_mapping, '
                       'blob_folder_data_set_mapping, kusto_cluster_data_set_mapping, kusto_database_data_set_mapping, '
                       'kusto_table_data_set_mapping, sqldb_table_data_set_mapping, sqldw_table_data_set_mapping, '
                       'synapse_workspace_sql_pool_table_data_set_mapping is needed for data_set_mapping!')
    if len(all_data_set_mapping) != 1:
        raise CLIError('data_set_mapping is required. but none of adls_gen2_file_data_set_mapping, '
                       'adls_gen2_file_system_data_set_mapping, adls_gen2_folder_data_set_mapping, '
                       'blob_container_data_set_mapping, blob_data_set_mapping, blob_folder_data_set_mapping, '
                       'kusto_cluster_data_set_mapping, kusto_database_data_set_mapping, kusto_table_data_set_mapping, '
                       'sqldb_table_data_set_mapping, sqldw_table_data_set_mapping, synapse_workspace_sql_pool_table_da'
                       'ta_set_mapping is provided!')
    data_set_mapping = all_data_set_mapping[0] if len(all_data_set_mapping) == 1 else None
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_subscription_name=share_subscription_name,
                         data_set_mapping_name=data_set_mapping_name,
                         data_set_mapping=data_set_mapping)


def datashare_data_set_mapping_delete(client,
                                      resource_group_name,
                                      account_name,
                                      share_subscription_name,
                                      data_set_mapping_name):
    return client.delete(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_subscription_name=share_subscription_name,
                         data_set_mapping_name=data_set_mapping_name)


def datashare_email_registration_activate_email(client,
                                                location,
                                                activation_code=None):
    email_registration = {}
    if activation_code is not None:
        email_registration['activation_code'] = activation_code
    return client.activate_email(location=location,
                                 email_registration=email_registration)


def datashare_email_registration_register_email(client,
                                                location):
    return client.register_email(location=location)


def datashare_invitation_list(client,
                              resource_group_name,
                              account_name,
                              share_name,
                              skip_token=None,
                              filter_=None,
                              orderby=None):
    return client.list_by_share(resource_group_name=resource_group_name,
                                account_name=account_name,
                                share_name=share_name,
                                skip_token=skip_token,
                                filter=filter_,
                                orderby=orderby)


def datashare_invitation_show(client,
                              resource_group_name,
                              account_name,
                              share_name,
                              invitation_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_name=share_name,
                      invitation_name=invitation_name)


def datashare_invitation_create(client,
                                resource_group_name,
                                account_name,
                                share_name,
                                invitation_name,
                                expiration_date=None,
                                target_active_directory_id=None,
                                target_email=None,
                                target_object_id=None):
    invitation = {}
    if expiration_date is not None:
        invitation['expiration_date'] = expiration_date
    if target_active_directory_id is not None:
        invitation['target_active_directory_id'] = target_active_directory_id
    if target_email is not None:
        invitation['target_email'] = target_email
    if target_object_id is not None:
        invitation['target_object_id'] = target_object_id
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         invitation_name=invitation_name,
                         invitation=invitation)


def datashare_invitation_delete(client,
                                resource_group_name,
                                account_name,
                                share_name,
                                invitation_name):
    return client.delete(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         invitation_name=invitation_name)


def datashare_list(client,
                   resource_group_name,
                   account_name,
                   skip_token=None,
                   filter_=None,
                   orderby=None):
    return client.list_by_account(resource_group_name=resource_group_name,
                                  account_name=account_name,
                                  skip_token=skip_token,
                                  filter=filter_,
                                  orderby=orderby)


def datashare_show(client,
                   resource_group_name,
                   account_name,
                   share_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_name=share_name)


def datashare_create(client,
                     resource_group_name,
                     account_name,
                     share_name,
                     description=None,
                     share_kind=None,
                     terms=None):
    share = {}
    if description is not None:
        share['description'] = description
    if share_kind is not None:
        share['share_kind'] = share_kind
    if terms is not None:
        share['terms'] = terms
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         share=share)


def datashare_delete(client,
                     resource_group_name,
                     account_name,
                     share_name,
                     no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_name=share_name)


def datashare_list_synchronization(client,
                                   resource_group_name,
                                   account_name,
                                   share_name,
                                   skip_token=None,
                                   filter_=None,
                                   orderby=None):
    return client.list_synchronizations(resource_group_name=resource_group_name,
                                        account_name=account_name,
                                        share_name=share_name,
                                        skip_token=skip_token,
                                        filter=filter_,
                                        orderby=orderby)


def datashare_list_synchronization_detail(client,
                                          resource_group_name,
                                          account_name,
                                          share_name,
                                          skip_token=None,
                                          filter_=None,
                                          orderby=None,
                                          consumer_email=None,
                                          consumer_name=None,
                                          consumer_tenant_name=None,
                                          duration_ms=None,
                                          end_time=None,
                                          message=None,
                                          start_time=None,
                                          status=None,
                                          synchronization_id=None):
    share_synchronization = {}
    if consumer_email is not None:
        share_synchronization['consumer_email'] = consumer_email
    if consumer_name is not None:
        share_synchronization['consumer_name'] = consumer_name
    if consumer_tenant_name is not None:
        share_synchronization['consumer_tenant_name'] = consumer_tenant_name
    if duration_ms is not None:
        share_synchronization['duration_ms'] = duration_ms
    if end_time is not None:
        share_synchronization['end_time'] = end_time
    if message is not None:
        share_synchronization['message'] = message
    if start_time is not None:
        share_synchronization['start_time'] = start_time
    if status is not None:
        share_synchronization['status'] = status
    if synchronization_id is not None:
        share_synchronization['synchronization_id'] = synchronization_id
    return client.list_synchronization_details(resource_group_name=resource_group_name,
                                               account_name=account_name,
                                               share_name=share_name,
                                               skip_token=skip_token,
                                               filter=filter_,
                                               orderby=orderby,
                                               share_synchronization=share_synchronization)


def datashare_provider_share_subscription_list(client,
                                               resource_group_name,
                                               account_name,
                                               share_name,
                                               skip_token=None):
    return client.list_by_share(resource_group_name=resource_group_name,
                                account_name=account_name,
                                share_name=share_name,
                                skip_token=skip_token)


def datashare_provider_share_subscription_show(client,
                                               resource_group_name,
                                               account_name,
                                               share_name,
                                               provider_share_subscription_id):
    return client.get_by_share(resource_group_name=resource_group_name,
                               account_name=account_name,
                               share_name=share_name,
                               provider_share_subscription_id=provider_share_subscription_id)


def datashare_provider_share_subscription_adjust(client,
                                                 resource_group_name,
                                                 account_name,
                                                 share_name,
                                                 provider_share_subscription_id,
                                                 expiration_date=None):
    provider_share_subscription = {}
    if expiration_date is not None:
        provider_share_subscription['expiration_date'] = expiration_date
    return client.adjust(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         provider_share_subscription_id=provider_share_subscription_id,
                         provider_share_subscription=provider_share_subscription)


def datashare_provider_share_subscription_reinstate(client,
                                                    resource_group_name,
                                                    account_name,
                                                    share_name,
                                                    provider_share_subscription_id,
                                                    expiration_date=None):
    provider_share_subscription = {}
    if expiration_date is not None:
        provider_share_subscription['expiration_date'] = expiration_date
    return client.reinstate(resource_group_name=resource_group_name,
                            account_name=account_name,
                            share_name=share_name,
                            provider_share_subscription_id=provider_share_subscription_id,
                            provider_share_subscription=provider_share_subscription)


def datashare_provider_share_subscription_revoke(client,
                                                 resource_group_name,
                                                 account_name,
                                                 share_name,
                                                 provider_share_subscription_id,
                                                 no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_revoke,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_name=share_name,
                       provider_share_subscription_id=provider_share_subscription_id)


def datashare_share_subscription_list(client,
                                      resource_group_name,
                                      account_name,
                                      skip_token=None,
                                      filter_=None,
                                      orderby=None):
    return client.list_by_account(resource_group_name=resource_group_name,
                                  account_name=account_name,
                                  skip_token=skip_token,
                                  filter=filter_,
                                  orderby=orderby)


def datashare_share_subscription_show(client,
                                      resource_group_name,
                                      account_name,
                                      share_subscription_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_subscription_name=share_subscription_name)


def datashare_share_subscription_create(client,
                                        resource_group_name,
                                        account_name,
                                        share_subscription_name,
                                        invitation_id,
                                        source_share_location,
                                        expiration_date=None):
    share_subscription = {}
    if expiration_date is not None:
        share_subscription['expiration_date'] = expiration_date
    share_subscription['invitation_id'] = invitation_id
    share_subscription['source_share_location'] = source_share_location
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_subscription_name=share_subscription_name,
                         share_subscription=share_subscription)


def datashare_share_subscription_delete(client,
                                        resource_group_name,
                                        account_name,
                                        share_subscription_name,
                                        no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_subscription_name=share_subscription_name)


def datashare_share_subscription_cancel_synchronization(client,
                                                        resource_group_name,
                                                        account_name,
                                                        share_subscription_name,
                                                        synchronization_id,
                                                        no_wait=False):
    share_subscription_synchronization = {}
    share_subscription_synchronization['synchronization_id'] = synchronization_id
    return sdk_no_wait(no_wait,
                       client.begin_cancel_synchronization,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_subscription_name=share_subscription_name,
                       share_subscription_synchronization=share_subscription_synchronization)


def datashare_share_subscription_list_source_share_synchronization_setting(client,
                                                                           resource_group_name,
                                                                           account_name,
                                                                           share_subscription_name,
                                                                           skip_token=None):
    return client.list_source_share_synchronization_settings(resource_group_name=resource_group_name,
                                                             account_name=account_name,
                                                             share_subscription_name=share_subscription_name,
                                                             skip_token=skip_token)


def datashare_share_subscription_list_synchronization(client,
                                                      resource_group_name,
                                                      account_name,
                                                      share_subscription_name,
                                                      skip_token=None,
                                                      filter_=None,
                                                      orderby=None):
    return client.list_synchronizations(resource_group_name=resource_group_name,
                                        account_name=account_name,
                                        share_subscription_name=share_subscription_name,
                                        skip_token=skip_token,
                                        filter=filter_,
                                        orderby=orderby)


def datashare_share_subscription_list_synchronization_detail(client,
                                                             resource_group_name,
                                                             account_name,
                                                             share_subscription_name,
                                                             synchronization_id,
                                                             skip_token=None,
                                                             filter_=None,
                                                             orderby=None):
    share_subscription_synchronization = {}
    share_subscription_synchronization['synchronization_id'] = synchronization_id
    return client.list_synchronization_details(resource_group_name=resource_group_name,
                                               account_name=account_name,
                                               share_subscription_name=share_subscription_name,
                                               skip_token=skip_token,
                                               filter=filter_,
                                               orderby=orderby,
                                               share_subscription_synchronization=share_subscription_synchronization)


def datashare_share_subscription_synchronize(client,
                                             resource_group_name,
                                             account_name,
                                             share_subscription_name,
                                             synchronization_mode=None,
                                             no_wait=False):
    synchronize = {}
    if synchronization_mode is not None:
        synchronize['synchronization_mode'] = synchronization_mode
    return sdk_no_wait(no_wait,
                       client.begin_synchronize,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_subscription_name=share_subscription_name,
                       synchronize=synchronize)


def datashare_consumer_source_data_set_list(client,
                                            resource_group_name,
                                            account_name,
                                            share_subscription_name,
                                            skip_token=None):
    return client.list_by_share_subscription(resource_group_name=resource_group_name,
                                             account_name=account_name,
                                             share_subscription_name=share_subscription_name,
                                             skip_token=skip_token)


def datashare_synchronization_setting_list(client,
                                           resource_group_name,
                                           account_name,
                                           share_name,
                                           skip_token=None):
    return client.list_by_share(resource_group_name=resource_group_name,
                                account_name=account_name,
                                share_name=share_name,
                                skip_token=skip_token)


def datashare_synchronization_setting_show(client,
                                           resource_group_name,
                                           account_name,
                                           share_name,
                                           synchronization_setting_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_name=share_name,
                      synchronization_setting_name=synchronization_setting_name)


def datashare_synchronization_setting_create(client,
                                             resource_group_name,
                                             account_name,
                                             share_name,
                                             synchronization_setting_name,
                                             scheduled_synchronization_setting=None):
    all_synchronization_setting = []
    if scheduled_synchronization_setting is not None:
        all_synchronization_setting.append(scheduled_synchronization_setting)
    if len(all_synchronization_setting) > 1:
        raise CLIError('at most one of  scheduled_synchronization_setting is needed for synchronization_setting!')
    if len(all_synchronization_setting) != 1:
        raise CLIError('synchronization_setting is required. but none of scheduled_synchronization_setting is '
                       'provided!')
    synchronization_setting = all_synchronization_setting[0] if len(all_synchronization_setting) == 1 else None
    return client.create(resource_group_name=resource_group_name,
                         account_name=account_name,
                         share_name=share_name,
                         synchronization_setting_name=synchronization_setting_name,
                         synchronization_setting=synchronization_setting)


def datashare_synchronization_setting_delete(client,
                                             resource_group_name,
                                             account_name,
                                             share_name,
                                             synchronization_setting_name,
                                             no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_name=share_name,
                       synchronization_setting_name=synchronization_setting_name)


def datashare_trigger_list(client,
                           resource_group_name,
                           account_name,
                           share_subscription_name,
                           skip_token=None):
    return client.list_by_share_subscription(resource_group_name=resource_group_name,
                                             account_name=account_name,
                                             share_subscription_name=share_subscription_name,
                                             skip_token=skip_token)


def datashare_trigger_show(client,
                           resource_group_name,
                           account_name,
                           share_subscription_name,
                           trigger_name):
    return client.get(resource_group_name=resource_group_name,
                      account_name=account_name,
                      share_subscription_name=share_subscription_name,
                      trigger_name=trigger_name)


def datashare_trigger_create(client,
                             resource_group_name,
                             account_name,
                             share_subscription_name,
                             trigger_name,
                             scheduled_trigger=None,
                             no_wait=False):
    all_trigger = []
    if scheduled_trigger is not None:
        all_trigger.append(scheduled_trigger)
    if len(all_trigger) > 1:
        raise CLIError('at most one of  scheduled_trigger is needed for trigger!')
    if len(all_trigger) != 1:
        raise CLIError('trigger is required. but none of scheduled_trigger is provided!')
    trigger = all_trigger[0] if len(all_trigger) == 1 else None
    return sdk_no_wait(no_wait,
                       client.begin_create,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_subscription_name=share_subscription_name,
                       trigger_name=trigger_name,
                       trigger=trigger)


def datashare_trigger_delete(client,
                             resource_group_name,
                             account_name,
                             share_subscription_name,
                             trigger_name,
                             no_wait=False):
    return sdk_no_wait(no_wait,
                       client.begin_delete,
                       resource_group_name=resource_group_name,
                       account_name=account_name,
                       share_subscription_name=share_subscription_name,
                       trigger_name=trigger_name)
