# --------------------------------------------------------------------------------------------
# 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(
    "site-recovery vault health refresh-default",
)
class RefreshDefault(AAZCommand):
    """Refresh default for the health of the vault.

    :example: health refresh-default
        az site-recovery vault health refresh-default -g rg --vault-name vault_name
    """

    _aaz_info = {
        "version": "2022-08-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.recoveryservices/vaults/{}/replicationvaulthealth/default/refresh", "2022-08-01"],
        ]
    }

    AZ_SUPPORT_NO_WAIT = True

    def _handler(self, command_args):
        super()._handler(command_args)
        return self.build_lro_poller(self._execute_operations, 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.vault_name = AAZStrArg(
            options=["--vault-name"],
            help="The name of the recovery services vault.",
            required=True,
            id_part="name",
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        yield self.ReplicationVaultHealthRefresh(ctx=self.ctx)()
        self.post_operations()

    @register_callback
    def pre_operations(self):
        pass

    @register_callback
    def post_operations(self):
        pass

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

    class ReplicationVaultHealthRefresh(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 [202]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )
            if session.http_response.status_code in [200]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200,
                    self.on_error,
                    lro_options={"final-state-via": "azure-async-operation"},
                    path_format_arguments=self.url_parameters,
                )

            return self.on_error(session.http_response)

        @property
        def url(self):
            return self.client.format_url(
                "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationVaultHealth/default/refresh",
                **self.url_parameters
            )

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

        @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(
                    "resourceName", self.ctx.args.vault_name,
                    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(
                    "api-version", "2022-08-01",
                    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.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.location = AAZStrType()
            _schema_on_200.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200.properties = AAZObjectType()
            _schema_on_200.type = AAZStrType(
                flags={"read_only": True},
            )

            properties = cls._schema_on_200.properties
            properties.containers_health = AAZObjectType(
                serialized_name="containersHealth",
            )
            _RefreshDefaultHelper._build_schema_resource_health_summary_read(properties.containers_health)
            properties.fabrics_health = AAZObjectType(
                serialized_name="fabricsHealth",
            )
            _RefreshDefaultHelper._build_schema_resource_health_summary_read(properties.fabrics_health)
            properties.protected_items_health = AAZObjectType(
                serialized_name="protectedItemsHealth",
            )
            _RefreshDefaultHelper._build_schema_resource_health_summary_read(properties.protected_items_health)
            properties.vault_errors = AAZListType(
                serialized_name="vaultErrors",
            )

            vault_errors = cls._schema_on_200.properties.vault_errors
            vault_errors.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.vault_errors.Element
            _element.creation_time_utc = AAZStrType(
                serialized_name="creationTimeUtc",
            )
            _element.customer_resolvability = AAZStrType(
                serialized_name="customerResolvability",
            )
            _element.entity_id = AAZStrType(
                serialized_name="entityId",
            )
            _element.error_category = AAZStrType(
                serialized_name="errorCategory",
            )
            _element.error_code = AAZStrType(
                serialized_name="errorCode",
            )
            _element.error_id = AAZStrType(
                serialized_name="errorId",
            )
            _element.error_level = AAZStrType(
                serialized_name="errorLevel",
            )
            _element.error_message = AAZStrType(
                serialized_name="errorMessage",
            )
            _element.error_source = AAZStrType(
                serialized_name="errorSource",
            )
            _element.error_type = AAZStrType(
                serialized_name="errorType",
            )
            _element.inner_health_errors = AAZListType(
                serialized_name="innerHealthErrors",
            )
            _element.possible_causes = AAZStrType(
                serialized_name="possibleCauses",
            )
            _element.recommended_action = AAZStrType(
                serialized_name="recommendedAction",
            )
            _element.recovery_provider_error_message = AAZStrType(
                serialized_name="recoveryProviderErrorMessage",
            )
            _element.summary_message = AAZStrType(
                serialized_name="summaryMessage",
            )

            inner_health_errors = cls._schema_on_200.properties.vault_errors.Element.inner_health_errors
            inner_health_errors.Element = AAZObjectType()

            _element = cls._schema_on_200.properties.vault_errors.Element.inner_health_errors.Element
            _element.creation_time_utc = AAZStrType(
                serialized_name="creationTimeUtc",
            )
            _element.customer_resolvability = AAZStrType(
                serialized_name="customerResolvability",
            )
            _element.entity_id = AAZStrType(
                serialized_name="entityId",
            )
            _element.error_category = AAZStrType(
                serialized_name="errorCategory",
            )
            _element.error_code = AAZStrType(
                serialized_name="errorCode",
            )
            _element.error_id = AAZStrType(
                serialized_name="errorId",
            )
            _element.error_level = AAZStrType(
                serialized_name="errorLevel",
            )
            _element.error_message = AAZStrType(
                serialized_name="errorMessage",
            )
            _element.error_source = AAZStrType(
                serialized_name="errorSource",
            )
            _element.error_type = AAZStrType(
                serialized_name="errorType",
            )
            _element.possible_causes = AAZStrType(
                serialized_name="possibleCauses",
            )
            _element.recommended_action = AAZStrType(
                serialized_name="recommendedAction",
            )
            _element.recovery_provider_error_message = AAZStrType(
                serialized_name="recoveryProviderErrorMessage",
            )
            _element.summary_message = AAZStrType(
                serialized_name="summaryMessage",
            )

            return cls._schema_on_200


class _RefreshDefaultHelper:
    """Helper class for RefreshDefault"""

    _schema_resource_health_summary_read = None

    @classmethod
    def _build_schema_resource_health_summary_read(cls, _schema):
        if cls._schema_resource_health_summary_read is not None:
            _schema.categorized_resource_counts = cls._schema_resource_health_summary_read.categorized_resource_counts
            _schema.issues = cls._schema_resource_health_summary_read.issues
            _schema.resource_count = cls._schema_resource_health_summary_read.resource_count
            return

        cls._schema_resource_health_summary_read = _schema_resource_health_summary_read = AAZObjectType()

        resource_health_summary_read = _schema_resource_health_summary_read
        resource_health_summary_read.categorized_resource_counts = AAZDictType(
            serialized_name="categorizedResourceCounts",
        )
        resource_health_summary_read.issues = AAZListType()
        resource_health_summary_read.resource_count = AAZIntType(
            serialized_name="resourceCount",
        )

        categorized_resource_counts = _schema_resource_health_summary_read.categorized_resource_counts
        categorized_resource_counts.Element = AAZIntType()

        issues = _schema_resource_health_summary_read.issues
        issues.Element = AAZObjectType()

        _element = _schema_resource_health_summary_read.issues.Element
        _element.affected_resource_correlation_ids = AAZListType(
            serialized_name="affectedResourceCorrelationIds",
        )
        _element.affected_resource_subtype = AAZStrType(
            serialized_name="affectedResourceSubtype",
        )
        _element.affected_resource_type = AAZStrType(
            serialized_name="affectedResourceType",
        )
        _element.category = AAZStrType()
        _element.severity = AAZStrType()
        _element.summary_code = AAZStrType(
            serialized_name="summaryCode",
        )
        _element.summary_message = AAZStrType(
            serialized_name="summaryMessage",
        )

        affected_resource_correlation_ids = _schema_resource_health_summary_read.issues.Element.affected_resource_correlation_ids
        affected_resource_correlation_ids.Element = AAZStrType()

        _schema.categorized_resource_counts = cls._schema_resource_health_summary_read.categorized_resource_counts
        _schema.issues = cls._schema_resource_health_summary_read.issues
        _schema.resource_count = cls._schema_resource_health_summary_read.resource_count


__all__ = ["RefreshDefault"]
