# --------------------------------------------------------------------------
# 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=protected-access

# pylint: disable=no-self-use


import argparse
from collections import defaultdict
from knack.util import CLIError


class AddLogzOrganizationProperties(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        namespace.logz_organization_properties = action

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'company-name':
                d['company_name'] = v[0]

            elif kl == 'enterprise-app-id':
                d['enterprise_app_id'] = v[0]

            elif kl == 'single-sign-on-url':
                d['single_sign_on_url'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter logz-organization-properties. All possible keys are:'
                    ' company-name, enterprise-app-id, single-sign-on-url'.format(k)
                )

        return d


class AddUserInfo(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        namespace.user_info = action

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'first-name':
                d['first_name'] = v[0]

            elif kl == 'last-name':
                d['last_name'] = v[0]

            elif kl == 'email-address':
                d['email_address'] = v[0]

            elif kl == 'phone-number':
                d['phone_number'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter user-info. All possible keys are: first-name,'
                    ' last-name, email-address, phone-number'.format(k)
                )

        return d


class AddPlanData(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        namespace.plan_data = action

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'usage-type':
                d['usage_type'] = v[0]

            elif kl == 'billing-cycle':
                d['billing_cycle'] = v[0]

            elif kl == 'plan-details':
                d['plan_details'] = v[0]

            elif kl == 'effective-date':
                d['effective_date'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter plan-data. All possible keys are: usage-type,'
                    ' billing-cycle, plan-details, effective-date'.format(k)
                )

        return d


class AddVmResourceIds(argparse._AppendAction):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        super(AddVmResourceIds, self).__call__(parser, namespace, action, option_string)

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'id':
                d['id'] = v[0]

            elif kl == 'agent-version':
                d['agent_version'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter vm-resource-ids. All possible keys are: id,'
                    ' agent-version'.format(k)
                )

        return d


class AddFilteringTags(argparse._AppendAction):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        super(AddFilteringTags, self).__call__(parser, namespace, action, option_string)

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'name':
                d['name'] = v[0]

            elif kl == 'value':
                d['value'] = v[0]

            elif kl == 'action':
                d['action'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter filtering-tags. All possible keys are: name, value,'
                    ' action'.format(k)
                )

        return d


class AddProperties(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        action = self.get_action(values, option_string)
        namespace.properties = action

    def get_action(self, values, option_string):
        try:
            properties = defaultdict(list)
            for (k, v) in (x.split('=', 1) for x in values):
                properties[k].append(v)
            properties = dict(properties)
        except ValueError:
            raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
        d = {}
        for k in properties:
            kl = k.lower()
            v = properties[k]

            if kl == 'single-sign-on-state':
                d['single_sign_on_state'] = v[0]

            elif kl == 'enterprise-app-id':
                d['enterprise_app_id'] = v[0]

            elif kl == 'single-sign-on-url':
                d['single_sign_on_url'] = v[0]

            else:
                raise CLIError(
                    'Unsupported Key {} is provided for parameter properties. All possible keys are:'
                    ' single-sign-on-state, enterprise-app-id, single-sign-on-url'.format(k)
                )

        return d
