# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
    "sentinel enrichment domain-whois show",
    is_experimental=True,
)
class Show(AAZCommand):
    """Get whois information for a single domain name
    """

    _aaz_info = {
        "version": "2022-06-01-preview",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.securityinsights/enrichment/domain/whois/", "2022-06-01-preview"],
        ]
    }

    def _handler(self, command_args):
        super()._handler(command_args)
        self._execute_operations()
        return self._output()

    _args_schema = None

    @classmethod
    def _build_arguments_schema(cls, *args, **kwargs):
        if cls._args_schema is not None:
            return cls._args_schema
        cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

        # define Arg Group ""

        _args_schema = cls._args_schema
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.domain = AAZStrArg(
            options=["--domain"],
            help="Domain name to be enriched",
            required=True,
        )
        return cls._args_schema

    def _execute_operations(self):
        self.DomainWhoisGet(ctx=self.ctx)()

    def _output(self, *args, **kwargs):
        result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
        return result

    class DomainWhoisGet(AAZHttpOperation):
        CLIENT_TYPE = "MgmtClient"

        def __call__(self, *args, **kwargs):
            request = self.make_request()
            session = self.client.send_request(request=request, stream=False, **kwargs)
            if session.http_response.status_code in [200]:
                return self.on_200(session)

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.SecurityInsights/enrichment/domain/whois/",
                **self.url_parameters
            )

        @property
        def method(self):
            return "GET"

        @property
        def error_format(self):
            return "ODataV4Format"

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "subscriptionId", self.ctx.subscription_id,
                    required=True,
                ),
            }
            return parameters

        @property
        def query_parameters(self):
            parameters = {
                **self.serialize_query_param(
                    "domain", self.ctx.args.domain,
                    required=True,
                ),
                **self.serialize_query_param(
                    "api-version", "2022-06-01-preview",
                    required=True,
                ),
            }
            return parameters

        @property
        def header_parameters(self):
            parameters = {
                **self.serialize_header_param(
                    "Accept", "application/json",
                ),
            }
            return parameters

        def on_200(self, session):
            data = self.deserialize_http_content(session)
            self.ctx.set_var(
                "instance",
                data,
                schema_builder=self._build_schema_on_200
            )

        _schema_on_200 = None

        @classmethod
        def _build_schema_on_200(cls):
            if cls._schema_on_200 is not None:
                return cls._schema_on_200

            cls._schema_on_200 = AAZObjectType()

            _schema_on_200 = cls._schema_on_200
            _schema_on_200.created = AAZStrType()
            _schema_on_200.domain = AAZStrType()
            _schema_on_200.expires = AAZStrType()
            _schema_on_200.parsed_whois = AAZObjectType(
                serialized_name="parsedWhois",
            )
            _schema_on_200.server = AAZStrType()
            _schema_on_200.updated = AAZStrType()

            parsed_whois = cls._schema_on_200.parsed_whois
            parsed_whois.contacts = AAZObjectType()
            parsed_whois.name_servers = AAZListType(
                serialized_name="nameServers",
            )
            parsed_whois.registrar = AAZObjectType()
            parsed_whois.statuses = AAZListType()

            contacts = cls._schema_on_200.parsed_whois.contacts
            contacts.admin = AAZObjectType()
            _build_schema_enrichment_domain_whois_contact_read(contacts.admin)
            contacts.billing = AAZObjectType()
            _build_schema_enrichment_domain_whois_contact_read(contacts.billing)
            contacts.registrant = AAZObjectType()
            _build_schema_enrichment_domain_whois_contact_read(contacts.registrant)
            contacts.tech = AAZObjectType()
            _build_schema_enrichment_domain_whois_contact_read(contacts.tech)

            name_servers = cls._schema_on_200.parsed_whois.name_servers
            name_servers.Element = AAZStrType()

            registrar = cls._schema_on_200.parsed_whois.registrar
            registrar.abuse_contact_email = AAZStrType(
                serialized_name="abuseContactEmail",
            )
            registrar.abuse_contact_phone = AAZStrType(
                serialized_name="abuseContactPhone",
            )
            registrar.iana_id = AAZStrType(
                serialized_name="ianaId",
            )
            registrar.name = AAZStrType()
            registrar.url = AAZStrType()
            registrar.whois_server = AAZStrType(
                serialized_name="whoisServer",
            )

            statuses = cls._schema_on_200.parsed_whois.statuses
            statuses.Element = AAZStrType()

            return cls._schema_on_200


_schema_enrichment_domain_whois_contact_read = None


def _build_schema_enrichment_domain_whois_contact_read(_schema):
    global _schema_enrichment_domain_whois_contact_read
    if _schema_enrichment_domain_whois_contact_read is not None:
        _schema.city = _schema_enrichment_domain_whois_contact_read.city
        _schema.country = _schema_enrichment_domain_whois_contact_read.country
        _schema.email = _schema_enrichment_domain_whois_contact_read.email
        _schema.fax = _schema_enrichment_domain_whois_contact_read.fax
        _schema.name = _schema_enrichment_domain_whois_contact_read.name
        _schema.org = _schema_enrichment_domain_whois_contact_read.org
        _schema.phone = _schema_enrichment_domain_whois_contact_read.phone
        _schema.postal = _schema_enrichment_domain_whois_contact_read.postal
        _schema.state = _schema_enrichment_domain_whois_contact_read.state
        _schema.street = _schema_enrichment_domain_whois_contact_read.street
        return

    _schema_enrichment_domain_whois_contact_read = AAZObjectType()

    enrichment_domain_whois_contact_read = _schema_enrichment_domain_whois_contact_read
    enrichment_domain_whois_contact_read.city = AAZStrType()
    enrichment_domain_whois_contact_read.country = AAZStrType()
    enrichment_domain_whois_contact_read.email = AAZStrType()
    enrichment_domain_whois_contact_read.fax = AAZStrType()
    enrichment_domain_whois_contact_read.name = AAZStrType()
    enrichment_domain_whois_contact_read.org = AAZStrType()
    enrichment_domain_whois_contact_read.phone = AAZStrType()
    enrichment_domain_whois_contact_read.postal = AAZStrType()
    enrichment_domain_whois_contact_read.state = AAZStrType()
    enrichment_domain_whois_contact_read.street = AAZListType()

    street = _schema_enrichment_domain_whois_contact_read.street
    street.Element = AAZStrType()

    _schema.city = _schema_enrichment_domain_whois_contact_read.city
    _schema.country = _schema_enrichment_domain_whois_contact_read.country
    _schema.email = _schema_enrichment_domain_whois_contact_read.email
    _schema.fax = _schema_enrichment_domain_whois_contact_read.fax
    _schema.name = _schema_enrichment_domain_whois_contact_read.name
    _schema.org = _schema_enrichment_domain_whois_contact_read.org
    _schema.phone = _schema_enrichment_domain_whois_contact_read.phone
    _schema.postal = _schema_enrichment_domain_whois_contact_read.postal
    _schema.state = _schema_enrichment_domain_whois_contact_read.state
    _schema.street = _schema_enrichment_domain_whois_contact_read.street


__all__ = ["Show"]
