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

if TYPE_CHECKING:
    from .import_post_response_failure_items import ImportPostResponse_failure_items
    from .import_post_response_success_items import ImportPostResponse_success_items

@dataclass
class ImportPostResponse(Parsable):
    # The failure property
    failure: Optional[int] = None
    # The failure_items property
    failure_items: Optional[list[ImportPostResponse_failure_items]] = None
    # The success property
    success: Optional[int] = None
    # The success_items property
    success_items: Optional[list[ImportPostResponse_success_items]] = None
    
    @staticmethod
    def create_from_discriminator_value(parse_node: ParseNode) -> ImportPostResponse:
        """
        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: ImportPostResponse
        """
        if parse_node is None:
            raise TypeError("parse_node cannot be null.")
        return ImportPostResponse()
    
    def get_field_deserializers(self,) -> dict[str, Callable[[ParseNode], None]]:
        """
        The deserialization information for the current model
        Returns: dict[str, Callable[[ParseNode], None]]
        """
        from .import_post_response_failure_items import ImportPostResponse_failure_items
        from .import_post_response_success_items import ImportPostResponse_success_items

        from .import_post_response_failure_items import ImportPostResponse_failure_items
        from .import_post_response_success_items import ImportPostResponse_success_items

        fields: dict[str, Callable[[Any], None]] = {
            "failure": lambda n : setattr(self, 'failure', n.get_int_value()),
            "failure_items": lambda n : setattr(self, 'failure_items', n.get_collection_of_object_values(ImportPostResponse_failure_items)),
            "success": lambda n : setattr(self, 'success', n.get_int_value()),
            "success_items": lambda n : setattr(self, 'success_items', n.get_collection_of_object_values(ImportPostResponse_success_items)),
        }
        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_int_value("failure", self.failure)
        writer.write_collection_of_object_values("failure_items", self.failure_items)
        writer.write_int_value("success", self.success)
        writer.write_collection_of_object_values("success_items", self.success_items)
    

