from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass, field
from kiota_abstractions.serialization import AdditionalDataHolder, Parsable, ParseNode, SerializationWriter
from typing import Any, Optional, TYPE_CHECKING, Union

if TYPE_CHECKING:
    from .alert import Alert
    from .rule_rule_status import Rule_RuleStatus

@dataclass
class Rule(AdditionalDataHolder, Parsable):
    # Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
    additional_data: dict[str, Any] = field(default_factory=dict)

    # List of alerts generated by the rule
    alerts: Optional[list[Alert]] = None
    # Number of alerts generated by the rule
    alerts_count: Optional[int] = None
    # Unique identifier of the rule
    rule_id: Optional[str] = None
    # Name of the rule
    rule_name: Optional[str] = None
    # Status of the rule
    rule_status: Optional[Rule_RuleStatus] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> Rule:
        """
        Creates a new instance of the appropriate class based on discriminator value
        param parse_node: The parse node to use to read the discriminator value and create the object
        Returns: Rule
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return Rule()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        from .alert import Alert
        from .rule_rule_status import Rule_RuleStatus

        from .alert import Alert
        from .rule_rule_status import Rule_RuleStatus

        fields: dict[str, Callable[[Any], None]] = {
            "Alerts": lambda n : setattr(self, 'alerts', n.get_collection_of_object_values(Alert)),
            "AlertsCount": lambda n : setattr(self, 'alerts_count', n.get_int_value()),
            "RuleId": lambda n : setattr(self, 'rule_id', n.get_str_value()),
            "RuleName": lambda n : setattr(self, 'rule_name', n.get_str_value()),
            "RuleStatus": lambda n : setattr(self, 'rule_status', n.get_enum_value(Rule_RuleStatus)),
        }
        return fields
    
    def serialize(self,writer: SerializationWriter) -> None:
        """
        Serializes information the current object
        param writer: Serialization writer to use to serialize this model
        Returns: None
        """
        if writer is None:
            raise TypeError("writer cannot be null.")
        writer.write_collection_of_object_values("Alerts", self.alerts)
        writer.write_int_value("AlertsCount", self.alerts_count)
        writer.write_str_value("RuleId", self.rule_id)
        writer.write_str_value("RuleName", self.rule_name)
        writer.write_enum_value("RuleStatus", self.rule_status)
        writer.write_additional_data_value(self.additional_data)
    

