# --------------------------------------------------------------------------------------------
# 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(
    "databox job list-credential",
)
class ListCredential(AAZCommand):
    """This method gets the unencrypted secrets related to the job.

    :example: List credential
        az databox job list-credential -g rg -n job-name
    """

    _aaz_info = {
        "version": "2022-12-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.databox/jobs/{}/listcredentials", "2022-12-01"],
        ]
    }

    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.job_name = AAZStrArg(
            options=["-n", "--name", "--job-name"],
            help="The name of the job Resource within the specified resource group. job names must be between 3 and 24 characters in length and use any alphanumeric and underscore only",
            required=True,
            id_part="name",
            fmt=AAZStrArgFormat(
                pattern="^[-\w\.]+$",
                max_length=24,
                min_length=3,
            ),
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        return cls._args_schema

    def _execute_operations(self):
        self.pre_operations()
        self.JobsListCredentials(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.value, client_flatten=True)
        return result

    class JobsListCredentials(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.DataBox/jobs/{jobName}/listCredentials",
                **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(
                    "jobName", self.ctx.args.job_name,
                    required=True,
                ),
                **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(
                    "api-version", "2022-12-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.next_link = AAZStrType(
                serialized_name="nextLink",
            )
            _schema_on_200.value = AAZListType()

            value = cls._schema_on_200.value
            value.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element
            _element.job_name = AAZStrType(
                serialized_name="jobName",
                flags={"read_only": True},
            )
            _element.job_secrets = AAZObjectType(
                serialized_name="jobSecrets",
            )

            job_secrets = cls._schema_on_200.value.Element.job_secrets
            job_secrets.dc_access_security_code = AAZObjectType(
                serialized_name="dcAccessSecurityCode",
            )
            job_secrets.error = AAZObjectType()
            _ListCredentialHelper._build_schema_cloud_error_read(job_secrets.error)
            job_secrets.job_secrets_type = AAZStrType(
                serialized_name="jobSecretsType",
                flags={"required": True},
            )

            dc_access_security_code = cls._schema_on_200.value.Element.job_secrets.dc_access_security_code
            dc_access_security_code.forward_dc_access_code = AAZStrType(
                serialized_name="forwardDCAccessCode",
            )
            dc_access_security_code.reverse_dc_access_code = AAZStrType(
                serialized_name="reverseDCAccessCode",
            )

            disc_data_box = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBox")
            disc_data_box.pod_secrets = AAZListType(
                serialized_name="podSecrets",
            )

            pod_secrets = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBox").pod_secrets
            pod_secrets.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBox").pod_secrets.Element
            _element.account_credential_details = AAZListType(
                serialized_name="accountCredentialDetails",
                flags={"read_only": True},
            )
            _element.device_password = AAZStrType(
                serialized_name="devicePassword",
                flags={"read_only": True},
            )
            _element.device_serial_number = AAZStrType(
                serialized_name="deviceSerialNumber",
                flags={"read_only": True},
            )
            _element.encoded_validation_cert_pub_key = AAZStrType(
                serialized_name="encodedValidationCertPubKey",
                flags={"read_only": True},
            )
            _element.network_configurations = AAZListType(
                serialized_name="networkConfigurations",
                flags={"read_only": True},
            )

            account_credential_details = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBox").pod_secrets.Element.account_credential_details
            account_credential_details.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_account_credential_details_read(account_credential_details.Element)

            network_configurations = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBox").pod_secrets.Element.network_configurations
            network_configurations.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_appliance_network_configuration_read(network_configurations.Element)

            disc_data_box_customer_disk = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxCustomerDisk")
            disc_data_box_customer_disk.carrier_account_number = AAZStrType(
                serialized_name="carrierAccountNumber",
                flags={"secret": True, "read_only": True},
            )
            disc_data_box_customer_disk.disk_secrets = AAZListType(
                serialized_name="diskSecrets",
                flags={"read_only": True},
            )

            disk_secrets = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxCustomerDisk").disk_secrets
            disk_secrets.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_disk_secret_read(disk_secrets.Element)

            disc_data_box_disk = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxDisk")
            disc_data_box_disk.disk_secrets = AAZListType(
                serialized_name="diskSecrets",
                flags={"read_only": True},
            )
            disc_data_box_disk.is_passkey_user_defined = AAZBoolType(
                serialized_name="isPasskeyUserDefined",
                flags={"read_only": True},
            )
            disc_data_box_disk.pass_key = AAZStrType(
                serialized_name="passKey",
                flags={"read_only": True},
            )

            disk_secrets = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxDisk").disk_secrets
            disk_secrets.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_disk_secret_read(disk_secrets.Element)

            disc_data_box_heavy = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxHeavy")
            disc_data_box_heavy.cabinet_pod_secrets = AAZListType(
                serialized_name="cabinetPodSecrets",
                flags={"read_only": True},
            )

            cabinet_pod_secrets = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxHeavy").cabinet_pod_secrets
            cabinet_pod_secrets.Element = AAZObjectType()

            _element = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxHeavy").cabinet_pod_secrets.Element
            _element.account_credential_details = AAZListType(
                serialized_name="accountCredentialDetails",
                flags={"read_only": True},
            )
            _element.device_password = AAZStrType(
                serialized_name="devicePassword",
                flags={"read_only": True},
            )
            _element.device_serial_number = AAZStrType(
                serialized_name="deviceSerialNumber",
                flags={"read_only": True},
            )
            _element.encoded_validation_cert_pub_key = AAZStrType(
                serialized_name="encodedValidationCertPubKey",
                flags={"read_only": True},
            )
            _element.network_configurations = AAZListType(
                serialized_name="networkConfigurations",
                flags={"read_only": True},
            )

            account_credential_details = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxHeavy").cabinet_pod_secrets.Element.account_credential_details
            account_credential_details.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_account_credential_details_read(account_credential_details.Element)

            network_configurations = cls._schema_on_200.value.Element.job_secrets.discriminate_by("job_secrets_type", "DataBoxHeavy").cabinet_pod_secrets.Element.network_configurations
            network_configurations.Element = AAZObjectType()
            _ListCredentialHelper._build_schema_appliance_network_configuration_read(network_configurations.Element)

            return cls._schema_on_200


class _ListCredentialHelper:
    """Helper class for ListCredential"""

    _schema_account_credential_details_read = None

    @classmethod
    def _build_schema_account_credential_details_read(cls, _schema):
        if cls._schema_account_credential_details_read is not None:
            _schema.account_connection_string = cls._schema_account_credential_details_read.account_connection_string
            _schema.account_name = cls._schema_account_credential_details_read.account_name
            _schema.data_account_type = cls._schema_account_credential_details_read.data_account_type
            _schema.share_credential_details = cls._schema_account_credential_details_read.share_credential_details
            return

        cls._schema_account_credential_details_read = _schema_account_credential_details_read = AAZObjectType()

        account_credential_details_read = _schema_account_credential_details_read
        account_credential_details_read.account_connection_string = AAZStrType(
            serialized_name="accountConnectionString",
            flags={"read_only": True},
        )
        account_credential_details_read.account_name = AAZStrType(
            serialized_name="accountName",
            flags={"read_only": True},
        )
        account_credential_details_read.data_account_type = AAZStrType(
            serialized_name="dataAccountType",
            flags={"read_only": True},
        )
        account_credential_details_read.share_credential_details = AAZListType(
            serialized_name="shareCredentialDetails",
            flags={"read_only": True},
        )

        share_credential_details = _schema_account_credential_details_read.share_credential_details
        share_credential_details.Element = AAZObjectType()

        _element = _schema_account_credential_details_read.share_credential_details.Element
        _element.password = AAZStrType(
            flags={"read_only": True},
        )
        _element.share_name = AAZStrType(
            serialized_name="shareName",
            flags={"read_only": True},
        )
        _element.share_type = AAZStrType(
            serialized_name="shareType",
            flags={"read_only": True},
        )
        _element.supported_access_protocols = AAZListType(
            serialized_name="supportedAccessProtocols",
            flags={"read_only": True},
        )
        _element.user_name = AAZStrType(
            serialized_name="userName",
            flags={"read_only": True},
        )

        supported_access_protocols = _schema_account_credential_details_read.share_credential_details.Element.supported_access_protocols
        supported_access_protocols.Element = AAZStrType()

        _schema.account_connection_string = cls._schema_account_credential_details_read.account_connection_string
        _schema.account_name = cls._schema_account_credential_details_read.account_name
        _schema.data_account_type = cls._schema_account_credential_details_read.data_account_type
        _schema.share_credential_details = cls._schema_account_credential_details_read.share_credential_details

    _schema_appliance_network_configuration_read = None

    @classmethod
    def _build_schema_appliance_network_configuration_read(cls, _schema):
        if cls._schema_appliance_network_configuration_read is not None:
            _schema.mac_address = cls._schema_appliance_network_configuration_read.mac_address
            _schema.name = cls._schema_appliance_network_configuration_read.name
            return

        cls._schema_appliance_network_configuration_read = _schema_appliance_network_configuration_read = AAZObjectType()

        appliance_network_configuration_read = _schema_appliance_network_configuration_read
        appliance_network_configuration_read.mac_address = AAZStrType(
            serialized_name="macAddress",
            flags={"read_only": True},
        )
        appliance_network_configuration_read.name = AAZStrType(
            flags={"read_only": True},
        )

        _schema.mac_address = cls._schema_appliance_network_configuration_read.mac_address
        _schema.name = cls._schema_appliance_network_configuration_read.name

    _schema_cloud_error_read = None

    @classmethod
    def _build_schema_cloud_error_read(cls, _schema):
        if cls._schema_cloud_error_read is not None:
            _schema.additional_info = cls._schema_cloud_error_read.additional_info
            _schema.code = cls._schema_cloud_error_read.code
            _schema.details = cls._schema_cloud_error_read.details
            _schema.message = cls._schema_cloud_error_read.message
            _schema.target = cls._schema_cloud_error_read.target
            return

        cls._schema_cloud_error_read = _schema_cloud_error_read = AAZObjectType()

        cloud_error_read = _schema_cloud_error_read
        cloud_error_read.additional_info = AAZListType(
            serialized_name="additionalInfo",
            flags={"read_only": True},
        )
        cloud_error_read.code = AAZStrType()
        cloud_error_read.details = AAZListType(
            flags={"read_only": True},
        )
        cloud_error_read.message = AAZStrType()
        cloud_error_read.target = AAZStrType()

        additional_info = _schema_cloud_error_read.additional_info
        additional_info.Element = AAZObjectType()

        _element = _schema_cloud_error_read.additional_info.Element
        _element.type = AAZStrType()

        details = _schema_cloud_error_read.details
        details.Element = AAZObjectType()
        cls._build_schema_cloud_error_read(details.Element)

        _schema.additional_info = cls._schema_cloud_error_read.additional_info
        _schema.code = cls._schema_cloud_error_read.code
        _schema.details = cls._schema_cloud_error_read.details
        _schema.message = cls._schema_cloud_error_read.message
        _schema.target = cls._schema_cloud_error_read.target

    _schema_disk_secret_read = None

    @classmethod
    def _build_schema_disk_secret_read(cls, _schema):
        if cls._schema_disk_secret_read is not None:
            _schema.bit_locker_key = cls._schema_disk_secret_read.bit_locker_key
            _schema.disk_serial_number = cls._schema_disk_secret_read.disk_serial_number
            return

        cls._schema_disk_secret_read = _schema_disk_secret_read = AAZObjectType()

        disk_secret_read = _schema_disk_secret_read
        disk_secret_read.bit_locker_key = AAZStrType(
            serialized_name="bitLockerKey",
            flags={"read_only": True},
        )
        disk_secret_read.disk_serial_number = AAZStrType(
            serialized_name="diskSerialNumber",
            flags={"read_only": True},
        )

        _schema.bit_locker_key = cls._schema_disk_secret_read.bit_locker_key
        _schema.disk_serial_number = cls._schema_disk_secret_read.disk_serial_number


__all__ = ["ListCredential"]
