# --------------------------------------------------------------------------------------------
# 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(
    "orbital spacecraft contact create",
)
class Create(AAZCommand):
    """Create a contact.

    :example: Create Contact
        az orbital spacecraft contact create -g <resource-group> --name <contact-name> --spacecraft-name <spacecraft-name> --contact-profile "{id:<contact-profile-id>}" --ground-station-name <ground-station-name> --reservation-start-time "2022-07-27T00:55:31.820Z" --reservation-end-time "2022-07-27T00:56:31.820Z"
    """

    _aaz_info = {
        "version": "2022-03-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.orbital/spacecrafts/{}/contacts/{}", "2022-03-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.contact_name = AAZStrArg(
            options=["-n", "--name", "--contact-name"],
            help="Contact name.",
            required=True,
            id_part="child_name_1",
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.spacecraft_name = AAZStrArg(
            options=["--spacecraft-name"],
            help="Spacecraft ID.",
            required=True,
            id_part="name",
        )

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.contact_profile = AAZObjectArg(
            options=["--contact-profile"],
            arg_group="Properties",
            help="The reference to the contact profile resource.",
        )
        _args_schema.ground_station_name = AAZStrArg(
            options=["--ground-station-name"],
            arg_group="Properties",
            help="Azure Ground Station name.",
        )
        _args_schema.reservation_end_time = AAZDateTimeArg(
            options=["--reservation-end-time"],
            arg_group="Properties",
            help="Reservation end time of a contact (ISO 8601 UTC standard).",
        )
        _args_schema.reservation_start_time = AAZDateTimeArg(
            options=["--reservation-start-time"],
            arg_group="Properties",
            help="Reservation start time of a contact (ISO 8601 UTC standard).",
        )

        contact_profile = cls._args_schema.contact_profile
        contact_profile.id = AAZStrArg(
            options=["id"],
            help="Resource ID.",
        )
        return cls._args_schema

    def _execute_operations(self):
        yield self.ContactsCreate(ctx=self.ctx)()

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

    class ContactsCreate(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_201,
                    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, 201]:
                return self.client.build_lro_polling(
                    self.ctx.args.no_wait,
                    session,
                    self.on_200_201,
                    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.Orbital/spacecrafts/{spacecraftName}/contacts/{contactName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "contactName", self.ctx.args.contact_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "spacecraftName", self.ctx.args.spacecraft_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-03-01",
                    required=True,
                ),
            }
            return parameters

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

        @property
        def content(self):
            _content_value, _builder = self.new_content_builder(
                self.ctx.args,
                typ=AAZObjectType,
                typ_kwargs={"flags": {"required": True, "client_flatten": True}}
            )
            _builder.set_prop("properties", AAZObjectType, typ_kwargs={"flags": {"client_flatten": True}})

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("contactProfile", AAZObjectType, ".contact_profile", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("groundStationName", AAZStrType, ".ground_station_name", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("reservationEndTime", AAZStrType, ".reservation_end_time", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("reservationStartTime", AAZStrType, ".reservation_start_time", typ_kwargs={"flags": {"required": True}})

            contact_profile = _builder.get(".properties.contactProfile")
            if contact_profile is not None:
                contact_profile.set_prop("id", AAZStrType, ".id")

            return self.serialize_content(_content_value)

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

        _schema_on_200_201 = None

        @classmethod
        def _build_schema_on_200_201(cls):
            if cls._schema_on_200_201 is not None:
                return cls._schema_on_200_201

            cls._schema_on_200_201 = AAZObjectType()

            _schema_on_200_201 = cls._schema_on_200_201
            _schema_on_200_201.etag = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.id = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.name = AAZStrType(
                flags={"read_only": True},
            )
            _schema_on_200_201.properties = AAZObjectType(
                flags={"client_flatten": True},
            )
            _schema_on_200_201.system_data = AAZObjectType(
                serialized_name="systemData",
                flags={"read_only": True},
            )
            _schema_on_200_201.type = AAZStrType(
                flags={"read_only": True},
            )

            properties = cls._schema_on_200_201.properties
            properties.antenna_configuration = AAZObjectType(
                serialized_name="antennaConfiguration",
                flags={"read_only": True},
            )
            properties.contact_profile = AAZObjectType(
                serialized_name="contactProfile",
                flags={"required": True},
            )
            properties.end_azimuth_degrees = AAZFloatType(
                serialized_name="endAzimuthDegrees",
                flags={"read_only": True},
            )
            properties.end_elevation_degrees = AAZFloatType(
                serialized_name="endElevationDegrees",
                flags={"read_only": True},
            )
            properties.error_message = AAZStrType(
                serialized_name="errorMessage",
                flags={"read_only": True},
            )
            properties.ground_station_name = AAZStrType(
                serialized_name="groundStationName",
                flags={"required": True},
            )
            properties.maximum_elevation_degrees = AAZFloatType(
                serialized_name="maximumElevationDegrees",
                flags={"read_only": True},
            )
            properties.provisioning_state = AAZStrType(
                serialized_name="provisioningState",
                flags={"read_only": True},
            )
            properties.reservation_end_time = AAZStrType(
                serialized_name="reservationEndTime",
                flags={"required": True},
            )
            properties.reservation_start_time = AAZStrType(
                serialized_name="reservationStartTime",
                flags={"required": True},
            )
            properties.rx_end_time = AAZStrType(
                serialized_name="rxEndTime",
                flags={"read_only": True},
            )
            properties.rx_start_time = AAZStrType(
                serialized_name="rxStartTime",
                flags={"read_only": True},
            )
            properties.start_azimuth_degrees = AAZFloatType(
                serialized_name="startAzimuthDegrees",
                flags={"read_only": True},
            )
            properties.start_elevation_degrees = AAZFloatType(
                serialized_name="startElevationDegrees",
                flags={"read_only": True},
            )
            properties.status = AAZStrType(
                flags={"read_only": True},
            )
            properties.tx_end_time = AAZStrType(
                serialized_name="txEndTime",
                flags={"read_only": True},
            )
            properties.tx_start_time = AAZStrType(
                serialized_name="txStartTime",
                flags={"read_only": True},
            )

            antenna_configuration = cls._schema_on_200_201.properties.antenna_configuration
            antenna_configuration.destination_ip = AAZStrType(
                serialized_name="destinationIp",
                flags={"read_only": True},
            )
            antenna_configuration.source_ips = AAZListType(
                serialized_name="sourceIps",
                flags={"read_only": True},
            )

            source_ips = cls._schema_on_200_201.properties.antenna_configuration.source_ips
            source_ips.Element = AAZStrType(
                flags={"read_only": True},
            )

            contact_profile = cls._schema_on_200_201.properties.contact_profile
            contact_profile.id = AAZStrType()

            system_data = cls._schema_on_200_201.system_data
            system_data.created_at = AAZStrType(
                serialized_name="createdAt",
                flags={"read_only": True},
            )
            system_data.created_by = AAZStrType(
                serialized_name="createdBy",
                flags={"read_only": True},
            )
            system_data.created_by_type = AAZStrType(
                serialized_name="createdByType",
                flags={"read_only": True},
            )
            system_data.last_modified_at = AAZStrType(
                serialized_name="lastModifiedAt",
                flags={"read_only": True},
            )
            system_data.last_modified_by = AAZStrType(
                serialized_name="lastModifiedBy",
                flags={"read_only": True},
            )
            system_data.last_modified_by_type = AAZStrType(
                serialized_name="lastModifiedByType",
                flags={"read_only": True},
            )

            return cls._schema_on_200_201


__all__ = ["Create"]
