# --------------------------------------------------------------------------------------------
# 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(
    "mobile-network service update",
)
class Update(AAZCommand):
    """Update a service.

    :example: Update service tags
        az mobile-network service update --mobile-network-name mobile-network-name -g rg -n service-name --tags "{tag:test,tag2:test2}"
    """

    _aaz_info = {
        "version": "2022-11-01",
        "resources": [
            ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.mobilenetwork/mobilenetworks/{}/services/{}", "2022-11-01"],
        ]
    }

    AZ_SUPPORT_NO_WAIT = True

    AZ_SUPPORT_GENERIC_UPDATE = 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.mobile_network_name = AAZStrArg(
            options=["--mobile-network-name"],
            help="The name of the mobile network.",
            required=True,
            id_part="name",
            fmt=AAZStrArgFormat(
                pattern="^[a-zA-Z0-9][a-zA-Z0-9_-]*$",
                max_length=64,
            ),
        )
        _args_schema.resource_group = AAZResourceGroupNameArg(
            required=True,
        )
        _args_schema.service_name = AAZStrArg(
            options=["-n", "--name", "--service-name"],
            help="The name of the service. You must not use any of the following reserved strings - `default`, `requested` or `service`",
            required=True,
            id_part="child_name_1",
            fmt=AAZStrArgFormat(
                pattern="^(?!(default|requested|service)$)[a-zA-Z0-9][a-zA-Z0-9_-]*$",
                max_length=64,
            ),
        )

        # define Arg Group "Parameters"

        _args_schema = cls._args_schema
        _args_schema.tags = AAZDictArg(
            options=["--tags"],
            arg_group="Parameters",
            help="Resource tags.",
            nullable=True,
        )

        tags = cls._args_schema.tags
        tags.Element = AAZStrArg(
            nullable=True,
        )

        # define Arg Group "Properties"

        _args_schema = cls._args_schema
        _args_schema.pcc_rules = AAZListArg(
            options=["--pcc-rules"],
            arg_group="Properties",
            help="The set of data flow policy rules that make up this service.",
            fmt=AAZListArgFormat(
                unique=True,
            ),
        )
        _args_schema.service_precedence = AAZIntArg(
            options=["--service-precedence"],
            arg_group="Properties",
            help="A precedence value that is used to decide between services when identifying the QoS values to use for a particular SIM. A lower value means a higher priority. This value should be unique among all services configured in the mobile network.",
            fmt=AAZIntArgFormat(
                maximum=255,
                minimum=0,
            ),
        )
        _args_schema.service_qos_policy = AAZObjectArg(
            options=["--service-qos-policy"],
            arg_group="Properties",
            help="The QoS policy to use for packets matching this service. This can be overridden for particular flows using the ruleQosPolicy field in a PccRuleConfiguration. If this field is null then the UE's SIM policy will define the QoS settings.",
            nullable=True,
        )

        pcc_rules = cls._args_schema.pcc_rules
        pcc_rules.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.pcc_rules.Element
        _element.rule_name = AAZStrArg(
            options=["rule-name"],
            help="The name of the rule. This must be unique within the parent service. You must not use any of the following reserved strings - `default`, `requested` or `service`.",
            fmt=AAZStrArgFormat(
                pattern="^(?!(default|requested|service)$)[a-zA-Z0-9][a-zA-Z0-9_-]*$",
                max_length=64,
            ),
        )
        _element.rule_precedence = AAZIntArg(
            options=["rule-precedence"],
            help="A precedence value that is used to decide between data flow policy rules when identifying the QoS values to use for a particular SIM. A lower value means a higher priority. This value should be unique among all data flow policy rules configured in the mobile network.",
            fmt=AAZIntArgFormat(
                maximum=255,
                minimum=0,
            ),
        )
        _element.rule_qos_policy = AAZObjectArg(
            options=["rule-qos-policy"],
            help="The QoS policy to use for packets matching this rule. If this field is null then the parent service will define the QoS settings.",
            nullable=True,
        )
        _element.service_data_flow_templates = AAZListArg(
            options=["service-data-flow-templates"],
            help="The set of data flow templates to use for this data flow policy rule.",
            fmt=AAZListArgFormat(
                unique=True,
            ),
        )
        _element.traffic_control = AAZStrArg(
            options=["traffic-control"],
            help="Determines whether flows that match this data flow policy rule are permitted.",
            nullable=True,
            enum={"Blocked": "Blocked", "Enabled": "Enabled"},
        )

        rule_qos_policy = cls._args_schema.pcc_rules.Element.rule_qos_policy
        rule_qos_policy.five_qi = AAZIntArg(
            options=["five-qi"],
            help="QoS Flow 5G QoS Indicator value. The 5QI identifies a specific QoS forwarding treatment to be provided to a flow. This must not be a standardized 5QI value corresponding to a GBR (guaranteed bit rate) QoS Flow. The illegal GBR 5QI values are: 1, 2, 3, 4, 65, 66, 67, 71, 72, 73, 74, 75, 76, 82, 83, 84, and 85. See 3GPP TS23.501 section 5.7.2.1 for a full description of the 5QI parameter, and table 5.7.4-1 for the definition of which are the GBR 5QI values.",
            nullable=True,
            fmt=AAZIntArgFormat(
                maximum=127,
                minimum=1,
            ),
        )
        rule_qos_policy.allocation_and_retention_priority_level = AAZIntArg(
            options=["allocation-and-retention-priority-level"],
            help="QoS Flow allocation and retention priority (ARP) level. Flows with higher priority preempt flows with lower priority, if the settings of `preemptionCapability` and `preemptionVulnerability` allow it. 1 is the highest level of priority. If this field is not specified then `5qi` is used to derive the ARP value. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            fmt=AAZIntArgFormat(
                maximum=15,
                minimum=1,
            ),
        )
        rule_qos_policy.guaranteed_bit_rate = AAZObjectArg(
            options=["guaranteed-bit-rate"],
            help="The guaranteed bit rate (GBR) for all service data flows that use this data flow policy rule. This is an optional setting. If you do not provide a value, there will be no GBR set for the data flow policy rule that uses this QoS definition.",
        )
        cls._build_args_ambr_update(rule_qos_policy.guaranteed_bit_rate)
        rule_qos_policy.maximum_bit_rate = AAZObjectArg(
            options=["maximum-bit-rate"],
            help="The maximum bit rate (MBR) for all service data flows that use this data flow policy rule or service.",
        )
        cls._build_args_ambr_update(rule_qos_policy.maximum_bit_rate)
        rule_qos_policy.preemption_capability = AAZStrArg(
            options=["preemption-capability"],
            help="QoS Flow preemption capability. The preemption capability of a QoS Flow controls whether it can preempt another QoS Flow with a lower priority level. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            enum={"MayPreempt": "MayPreempt", "NotPreempt": "NotPreempt"},
        )
        rule_qos_policy.preemption_vulnerability = AAZStrArg(
            options=["preemption-vulnerability"],
            help="QoS Flow preemption vulnerability. The preemption vulnerability of a QoS Flow controls whether it can be preempted by a QoS Flow with a higher priority level. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            enum={"NotPreemptable": "NotPreemptable", "Preemptable": "Preemptable"},
        )

        service_data_flow_templates = cls._args_schema.pcc_rules.Element.service_data_flow_templates
        service_data_flow_templates.Element = AAZObjectArg(
            nullable=True,
        )

        _element = cls._args_schema.pcc_rules.Element.service_data_flow_templates.Element
        _element.direction = AAZStrArg(
            options=["direction"],
            help="The direction of this flow.",
            enum={"Bidirectional": "Bidirectional", "Downlink": "Downlink", "Uplink": "Uplink"},
        )
        _element.ports = AAZListArg(
            options=["ports"],
            help="The port(s) to which UEs will connect for this flow. You can specify zero or more ports or port ranges. If you specify one or more ports or port ranges then you must specify a value other than `ip` in the `protocol` field. This is an optional setting. If you do not specify it then connections will be allowed on all ports. Port ranges must be specified as <FirstPort>-<LastPort>. For example: [`8080`, `8082-8085`].",
            nullable=True,
            fmt=AAZListArgFormat(
                unique=True,
            ),
        )
        _element.protocol = AAZListArg(
            options=["protocol"],
            help="A list of the allowed protocol(s) for this flow. If you want this flow to be able to use any protocol within the internet protocol suite, use the value `ip`. If you only want to allow a selection of protocols, you must use the corresponding IANA Assigned Internet Protocol Number for each protocol, as described in https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml. For example, for UDP, you must use 17. If you use the value `ip` then you must leave the field `port` unspecified.",
            fmt=AAZListArgFormat(
                unique=True,
            ),
        )
        _element.remote_ip_list = AAZListArg(
            options=["remote-ip-list"],
            help="The remote IP address(es) to which UEs will connect for this flow. If you want to allow connections on any IP address, use the value `any`. Otherwise, you must provide each of the remote IP addresses to which the packet core instance will connect for this flow. You must provide each IP address in CIDR notation, including the netmask (for example, 192.0.2.54/24).",
            fmt=AAZListArgFormat(
                unique=True,
            ),
        )
        _element.template_name = AAZStrArg(
            options=["template-name"],
            help="The name of the data flow template. This must be unique within the parent data flow policy rule. You must not use any of the following reserved strings - `default`, `requested` or `service`.",
            fmt=AAZStrArgFormat(
                pattern="^(?!(default|requested|service)$)[a-zA-Z0-9][a-zA-Z0-9_-]*$",
                max_length=64,
            ),
        )

        ports = cls._args_schema.pcc_rules.Element.service_data_flow_templates.Element.ports
        ports.Element = AAZStrArg(
            nullable=True,
            fmt=AAZStrArgFormat(
                pattern="^([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])(-([1-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$",
            ),
        )

        protocol = cls._args_schema.pcc_rules.Element.service_data_flow_templates.Element.protocol
        protocol.Element = AAZStrArg(
            nullable=True,
            fmt=AAZStrArgFormat(
                pattern="^(ip|[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$",
            ),
        )

        remote_ip_list = cls._args_schema.pcc_rules.Element.service_data_flow_templates.Element.remote_ip_list
        remote_ip_list.Element = AAZStrArg(
            nullable=True,
            fmt=AAZStrArgFormat(
                pattern="^(any|(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2])))$",
            ),
        )

        service_qos_policy = cls._args_schema.service_qos_policy
        service_qos_policy.five_qi = AAZIntArg(
            options=["five-qi"],
            help="QoS Flow 5G QoS Indicator value. The 5QI identifies a specific QoS forwarding treatment to be provided to a flow. This must not be a standardized 5QI value corresponding to a GBR (guaranteed bit rate) QoS Flow. The illegal GBR 5QI values are: 1, 2, 3, 4, 65, 66, 67, 71, 72, 73, 74, 75, 76, 82, 83, 84, and 85. See 3GPP TS23.501 section 5.7.2.1 for a full description of the 5QI parameter, and table 5.7.4-1 for the definition of which are the GBR 5QI values.",
            nullable=True,
            fmt=AAZIntArgFormat(
                maximum=127,
                minimum=1,
            ),
        )
        service_qos_policy.allocation_and_retention_priority_level = AAZIntArg(
            options=["allocation-and-retention-priority-level"],
            help="QoS Flow allocation and retention priority (ARP) level. Flows with higher priority preempt flows with lower priority, if the settings of `preemptionCapability` and `preemptionVulnerability` allow it. 1 is the highest level of priority. If this field is not specified then `5qi` is used to derive the ARP value. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            fmt=AAZIntArgFormat(
                maximum=15,
                minimum=1,
            ),
        )
        service_qos_policy.maximum_bit_rate = AAZObjectArg(
            options=["maximum-bit-rate"],
            help="The maximum bit rate (MBR) for all service data flows that use this data flow policy rule or service.",
        )
        cls._build_args_ambr_update(service_qos_policy.maximum_bit_rate)
        service_qos_policy.preemption_capability = AAZStrArg(
            options=["preemption-capability"],
            help="QoS Flow preemption capability. The preemption capability of a QoS Flow controls whether it can preempt another QoS Flow with a lower priority level. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            enum={"MayPreempt": "MayPreempt", "NotPreempt": "NotPreempt"},
        )
        service_qos_policy.preemption_vulnerability = AAZStrArg(
            options=["preemption-vulnerability"],
            help="QoS Flow preemption vulnerability. The preemption vulnerability of a QoS Flow controls whether it can be preempted by a QoS Flow with a higher priority level. See 3GPP TS23.501 section 5.7.2.2 for a full description of the ARP parameters.",
            nullable=True,
            enum={"NotPreemptable": "NotPreemptable", "Preemptable": "Preemptable"},
        )
        return cls._args_schema

    _args_ambr_update = None

    @classmethod
    def _build_args_ambr_update(cls, _schema):
        if cls._args_ambr_update is not None:
            _schema.downlink = cls._args_ambr_update.downlink
            _schema.uplink = cls._args_ambr_update.uplink
            return

        cls._args_ambr_update = AAZObjectArg()

        ambr_update = cls._args_ambr_update
        ambr_update.downlink = AAZStrArg(
            options=["downlink"],
            help="Downlink bit rate.",
            fmt=AAZStrArgFormat(
                pattern="^\d+(\.\d+)? (bps|Kbps|Mbps|Gbps|Tbps)$",
            ),
        )
        ambr_update.uplink = AAZStrArg(
            options=["uplink"],
            help="Uplink bit rate.",
            fmt=AAZStrArgFormat(
                pattern="^\d+(\.\d+)? (bps|Kbps|Mbps|Gbps|Tbps)$",
            ),
        )

        _schema.downlink = cls._args_ambr_update.downlink
        _schema.uplink = cls._args_ambr_update.uplink

    def _execute_operations(self):
        self.pre_operations()
        self.ServicesGet(ctx=self.ctx)()
        self.pre_instance_update(self.ctx.vars.instance)
        self.InstanceUpdateByJson(ctx=self.ctx)()
        self.InstanceUpdateByGeneric(ctx=self.ctx)()
        self.post_instance_update(self.ctx.vars.instance)
        yield self.ServicesCreateOrUpdate(ctx=self.ctx)()
        self.post_operations()

    @register_callback
    def pre_operations(self):
        pass

    @register_callback
    def post_operations(self):
        pass

    @register_callback
    def pre_instance_update(self, instance):
        pass

    @register_callback
    def post_instance_update(self, instance):
        pass

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

    class ServicesGet(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.MobileNetwork/mobileNetworks/{mobileNetworkName}/services/{serviceName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "mobileNetworkName", self.ctx.args.mobile_network_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "serviceName", self.ctx.args.service_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-11-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()
            _UpdateHelper._build_schema_service_read(cls._schema_on_200)

            return cls._schema_on_200

    class ServicesCreateOrUpdate(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.MobileNetwork/mobileNetworks/{mobileNetworkName}/services/{serviceName}",
                **self.url_parameters
            )

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

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

        @property
        def url_parameters(self):
            parameters = {
                **self.serialize_url_param(
                    "mobileNetworkName", self.ctx.args.mobile_network_name,
                    required=True,
                ),
                **self.serialize_url_param(
                    "resourceGroupName", self.ctx.args.resource_group,
                    required=True,
                ),
                **self.serialize_url_param(
                    "serviceName", self.ctx.args.service_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-11-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,
                value=self.ctx.vars.instance,
            )

            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()
            _UpdateHelper._build_schema_service_read(cls._schema_on_200_201)

            return cls._schema_on_200_201

    class InstanceUpdateByJson(AAZJsonInstanceUpdateOperation):

        def __call__(self, *args, **kwargs):
            self._update_instance(self.ctx.vars.instance)

        def _update_instance(self, instance):
            _instance_value, _builder = self.new_content_builder(
                self.ctx.args,
                value=instance,
                typ=AAZObjectType
            )
            _builder.set_prop("properties", AAZObjectType, ".", typ_kwargs={"flags": {"required": True, "client_flatten": True}})
            _builder.set_prop("tags", AAZDictType, ".tags")

            properties = _builder.get(".properties")
            if properties is not None:
                properties.set_prop("pccRules", AAZListType, ".pcc_rules", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("servicePrecedence", AAZIntType, ".service_precedence", typ_kwargs={"flags": {"required": True}})
                properties.set_prop("serviceQosPolicy", AAZObjectType, ".service_qos_policy")

            pcc_rules = _builder.get(".properties.pccRules")
            if pcc_rules is not None:
                pcc_rules.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.pccRules[]")
            if _elements is not None:
                _elements.set_prop("ruleName", AAZStrType, ".rule_name", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("rulePrecedence", AAZIntType, ".rule_precedence", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("ruleQosPolicy", AAZObjectType, ".rule_qos_policy")
                _elements.set_prop("serviceDataFlowTemplates", AAZListType, ".service_data_flow_templates", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("trafficControl", AAZStrType, ".traffic_control")

            rule_qos_policy = _builder.get(".properties.pccRules[].ruleQosPolicy")
            if rule_qos_policy is not None:
                rule_qos_policy.set_prop("5qi", AAZIntType, ".five_qi")
                rule_qos_policy.set_prop("allocationAndRetentionPriorityLevel", AAZIntType, ".allocation_and_retention_priority_level")
                _UpdateHelper._build_schema_ambr_update(rule_qos_policy.set_prop("guaranteedBitRate", AAZObjectType, ".guaranteed_bit_rate"))
                _UpdateHelper._build_schema_ambr_update(rule_qos_policy.set_prop("maximumBitRate", AAZObjectType, ".maximum_bit_rate", typ_kwargs={"flags": {"required": True}}))
                rule_qos_policy.set_prop("preemptionCapability", AAZStrType, ".preemption_capability")
                rule_qos_policy.set_prop("preemptionVulnerability", AAZStrType, ".preemption_vulnerability")

            service_data_flow_templates = _builder.get(".properties.pccRules[].serviceDataFlowTemplates")
            if service_data_flow_templates is not None:
                service_data_flow_templates.set_elements(AAZObjectType, ".")

            _elements = _builder.get(".properties.pccRules[].serviceDataFlowTemplates[]")
            if _elements is not None:
                _elements.set_prop("direction", AAZStrType, ".direction", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("ports", AAZListType, ".ports")
                _elements.set_prop("protocol", AAZListType, ".protocol", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("remoteIpList", AAZListType, ".remote_ip_list", typ_kwargs={"flags": {"required": True}})
                _elements.set_prop("templateName", AAZStrType, ".template_name", typ_kwargs={"flags": {"required": True}})

            ports = _builder.get(".properties.pccRules[].serviceDataFlowTemplates[].ports")
            if ports is not None:
                ports.set_elements(AAZStrType, ".")

            protocol = _builder.get(".properties.pccRules[].serviceDataFlowTemplates[].protocol")
            if protocol is not None:
                protocol.set_elements(AAZStrType, ".")

            remote_ip_list = _builder.get(".properties.pccRules[].serviceDataFlowTemplates[].remoteIpList")
            if remote_ip_list is not None:
                remote_ip_list.set_elements(AAZStrType, ".")

            service_qos_policy = _builder.get(".properties.serviceQosPolicy")
            if service_qos_policy is not None:
                service_qos_policy.set_prop("5qi", AAZIntType, ".five_qi")
                service_qos_policy.set_prop("allocationAndRetentionPriorityLevel", AAZIntType, ".allocation_and_retention_priority_level")
                _UpdateHelper._build_schema_ambr_update(service_qos_policy.set_prop("maximumBitRate", AAZObjectType, ".maximum_bit_rate", typ_kwargs={"flags": {"required": True}}))
                service_qos_policy.set_prop("preemptionCapability", AAZStrType, ".preemption_capability")
                service_qos_policy.set_prop("preemptionVulnerability", AAZStrType, ".preemption_vulnerability")

            tags = _builder.get(".tags")
            if tags is not None:
                tags.set_elements(AAZStrType, ".")

            return _instance_value

    class InstanceUpdateByGeneric(AAZGenericInstanceUpdateOperation):

        def __call__(self, *args, **kwargs):
            self._update_instance_by_generic(
                self.ctx.vars.instance,
                self.ctx.generic_update_args
            )


class _UpdateHelper:
    """Helper class for Update"""

    @classmethod
    def _build_schema_ambr_update(cls, _builder):
        if _builder is None:
            return
        _builder.set_prop("downlink", AAZStrType, ".downlink", typ_kwargs={"flags": {"required": True}})
        _builder.set_prop("uplink", AAZStrType, ".uplink", typ_kwargs={"flags": {"required": True}})

    _schema_ambr_read = None

    @classmethod
    def _build_schema_ambr_read(cls, _schema):
        if cls._schema_ambr_read is not None:
            _schema.downlink = cls._schema_ambr_read.downlink
            _schema.uplink = cls._schema_ambr_read.uplink
            return

        cls._schema_ambr_read = _schema_ambr_read = AAZObjectType()

        ambr_read = _schema_ambr_read
        ambr_read.downlink = AAZStrType(
            flags={"required": True},
        )
        ambr_read.uplink = AAZStrType(
            flags={"required": True},
        )

        _schema.downlink = cls._schema_ambr_read.downlink
        _schema.uplink = cls._schema_ambr_read.uplink

    _schema_service_read = None

    @classmethod
    def _build_schema_service_read(cls, _schema):
        if cls._schema_service_read is not None:
            _schema.id = cls._schema_service_read.id
            _schema.location = cls._schema_service_read.location
            _schema.name = cls._schema_service_read.name
            _schema.properties = cls._schema_service_read.properties
            _schema.system_data = cls._schema_service_read.system_data
            _schema.tags = cls._schema_service_read.tags
            _schema.type = cls._schema_service_read.type
            return

        cls._schema_service_read = _schema_service_read = AAZObjectType()

        service_read = _schema_service_read
        service_read.id = AAZStrType(
            flags={"read_only": True},
        )
        service_read.location = AAZStrType(
            flags={"required": True},
        )
        service_read.name = AAZStrType(
            flags={"read_only": True},
        )
        service_read.properties = AAZObjectType(
            flags={"required": True, "client_flatten": True},
        )
        service_read.system_data = AAZObjectType(
            serialized_name="systemData",
            flags={"read_only": True},
        )
        service_read.tags = AAZDictType()
        service_read.type = AAZStrType(
            flags={"read_only": True},
        )

        properties = _schema_service_read.properties
        properties.pcc_rules = AAZListType(
            serialized_name="pccRules",
            flags={"required": True},
        )
        properties.provisioning_state = AAZStrType(
            serialized_name="provisioningState",
            flags={"read_only": True},
        )
        properties.service_precedence = AAZIntType(
            serialized_name="servicePrecedence",
            flags={"required": True},
        )
        properties.service_qos_policy = AAZObjectType(
            serialized_name="serviceQosPolicy",
        )

        pcc_rules = _schema_service_read.properties.pcc_rules
        pcc_rules.Element = AAZObjectType()

        _element = _schema_service_read.properties.pcc_rules.Element
        _element.rule_name = AAZStrType(
            serialized_name="ruleName",
            flags={"required": True},
        )
        _element.rule_precedence = AAZIntType(
            serialized_name="rulePrecedence",
            flags={"required": True},
        )
        _element.rule_qos_policy = AAZObjectType(
            serialized_name="ruleQosPolicy",
        )
        _element.service_data_flow_templates = AAZListType(
            serialized_name="serviceDataFlowTemplates",
            flags={"required": True},
        )
        _element.traffic_control = AAZStrType(
            serialized_name="trafficControl",
        )

        rule_qos_policy = _schema_service_read.properties.pcc_rules.Element.rule_qos_policy
        rule_qos_policy["5qi"] = AAZIntType()
        rule_qos_policy.allocation_and_retention_priority_level = AAZIntType(
            serialized_name="allocationAndRetentionPriorityLevel",
        )
        rule_qos_policy.guaranteed_bit_rate = AAZObjectType(
            serialized_name="guaranteedBitRate",
        )
        cls._build_schema_ambr_read(rule_qos_policy.guaranteed_bit_rate)
        rule_qos_policy.maximum_bit_rate = AAZObjectType(
            serialized_name="maximumBitRate",
            flags={"required": True},
        )
        cls._build_schema_ambr_read(rule_qos_policy.maximum_bit_rate)
        rule_qos_policy.preemption_capability = AAZStrType(
            serialized_name="preemptionCapability",
        )
        rule_qos_policy.preemption_vulnerability = AAZStrType(
            serialized_name="preemptionVulnerability",
        )

        service_data_flow_templates = _schema_service_read.properties.pcc_rules.Element.service_data_flow_templates
        service_data_flow_templates.Element = AAZObjectType()

        _element = _schema_service_read.properties.pcc_rules.Element.service_data_flow_templates.Element
        _element.direction = AAZStrType(
            flags={"required": True},
        )
        _element.ports = AAZListType()
        _element.protocol = AAZListType(
            flags={"required": True},
        )
        _element.remote_ip_list = AAZListType(
            serialized_name="remoteIpList",
            flags={"required": True},
        )
        _element.template_name = AAZStrType(
            serialized_name="templateName",
            flags={"required": True},
        )

        ports = _schema_service_read.properties.pcc_rules.Element.service_data_flow_templates.Element.ports
        ports.Element = AAZStrType()

        protocol = _schema_service_read.properties.pcc_rules.Element.service_data_flow_templates.Element.protocol
        protocol.Element = AAZStrType()

        remote_ip_list = _schema_service_read.properties.pcc_rules.Element.service_data_flow_templates.Element.remote_ip_list
        remote_ip_list.Element = AAZStrType()

        service_qos_policy = _schema_service_read.properties.service_qos_policy
        service_qos_policy["5qi"] = AAZIntType()
        service_qos_policy.allocation_and_retention_priority_level = AAZIntType(
            serialized_name="allocationAndRetentionPriorityLevel",
        )
        service_qos_policy.maximum_bit_rate = AAZObjectType(
            serialized_name="maximumBitRate",
            flags={"required": True},
        )
        cls._build_schema_ambr_read(service_qos_policy.maximum_bit_rate)
        service_qos_policy.preemption_capability = AAZStrType(
            serialized_name="preemptionCapability",
        )
        service_qos_policy.preemption_vulnerability = AAZStrType(
            serialized_name="preemptionVulnerability",
        )

        system_data = _schema_service_read.system_data
        system_data.created_at = AAZStrType(
            serialized_name="createdAt",
        )
        system_data.created_by = AAZStrType(
            serialized_name="createdBy",
        )
        system_data.created_by_type = AAZStrType(
            serialized_name="createdByType",
        )
        system_data.last_modified_at = AAZStrType(
            serialized_name="lastModifiedAt",
        )
        system_data.last_modified_by = AAZStrType(
            serialized_name="lastModifiedBy",
        )
        system_data.last_modified_by_type = AAZStrType(
            serialized_name="lastModifiedByType",
        )

        tags = _schema_service_read.tags
        tags.Element = AAZStrType()

        _schema.id = cls._schema_service_read.id
        _schema.location = cls._schema_service_read.location
        _schema.name = cls._schema_service_read.name
        _schema.properties = cls._schema_service_read.properties
        _schema.system_data = cls._schema_service_read.system_data
        _schema.tags = cls._schema_service_read.tags
        _schema.type = cls._schema_service_read.type


__all__ = ["Update"]
