# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, TypeVar, Union

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.testrun_comments_list_get_response_data_item_relationships_author import (
        TestrunCommentsListGetResponseDataItemRelationshipsAuthor,
    )
    from ..models.testrun_comments_list_get_response_data_item_relationships_child_comments import (
        TestrunCommentsListGetResponseDataItemRelationshipsChildComments,
    )
    from ..models.testrun_comments_list_get_response_data_item_relationships_parent_comment import (
        TestrunCommentsListGetResponseDataItemRelationshipsParentComment,
    )
    from ..models.testrun_comments_list_get_response_data_item_relationships_project import (
        TestrunCommentsListGetResponseDataItemRelationshipsProject,
    )


T = TypeVar("T", bound="TestrunCommentsListGetResponseDataItemRelationships")


@_attrs_define
class TestrunCommentsListGetResponseDataItemRelationships:
    """
    Attributes:
        author (Union[Unset, TestrunCommentsListGetResponseDataItemRelationshipsAuthor]):
        child_comments (Union[Unset, TestrunCommentsListGetResponseDataItemRelationshipsChildComments]):
        parent_comment (Union[Unset, TestrunCommentsListGetResponseDataItemRelationshipsParentComment]):
        project (Union[Unset, TestrunCommentsListGetResponseDataItemRelationshipsProject]):
    """

    author: Union[
        Unset, "TestrunCommentsListGetResponseDataItemRelationshipsAuthor"
    ] = UNSET
    child_comments: Union[
        Unset,
        "TestrunCommentsListGetResponseDataItemRelationshipsChildComments",
    ] = UNSET
    parent_comment: Union[
        Unset,
        "TestrunCommentsListGetResponseDataItemRelationshipsParentComment",
    ] = UNSET
    project: Union[
        Unset, "TestrunCommentsListGetResponseDataItemRelationshipsProject"
    ] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(
        init=False, factory=dict
    )

    def to_dict(self) -> dict[str, Any]:
        author: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.author, Unset):
            author = self.author.to_dict()

        child_comments: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.child_comments, Unset):
            child_comments = self.child_comments.to_dict()

        parent_comment: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.parent_comment, Unset):
            parent_comment = self.parent_comment.to_dict()

        project: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.project, Unset):
            project = self.project.to_dict()

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if author is not UNSET:
            field_dict["author"] = author
        if child_comments is not UNSET:
            field_dict["childComments"] = child_comments
        if parent_comment is not UNSET:
            field_dict["parentComment"] = parent_comment
        if project is not UNSET:
            field_dict["project"] = project

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.testrun_comments_list_get_response_data_item_relationships_author import (
            TestrunCommentsListGetResponseDataItemRelationshipsAuthor,
        )
        from ..models.testrun_comments_list_get_response_data_item_relationships_child_comments import (
            TestrunCommentsListGetResponseDataItemRelationshipsChildComments,
        )
        from ..models.testrun_comments_list_get_response_data_item_relationships_parent_comment import (
            TestrunCommentsListGetResponseDataItemRelationshipsParentComment,
        )
        from ..models.testrun_comments_list_get_response_data_item_relationships_project import (
            TestrunCommentsListGetResponseDataItemRelationshipsProject,
        )

        d = dict(src_dict)
        _author = d.pop("author", UNSET)
        author: Union[
            Unset, TestrunCommentsListGetResponseDataItemRelationshipsAuthor
        ]
        if isinstance(_author, Unset):
            author = UNSET
        else:
            author = TestrunCommentsListGetResponseDataItemRelationshipsAuthor.from_dict(
                _author
            )

        _child_comments = d.pop("childComments", UNSET)
        child_comments: Union[
            Unset,
            TestrunCommentsListGetResponseDataItemRelationshipsChildComments,
        ]
        if isinstance(_child_comments, Unset):
            child_comments = UNSET
        else:
            child_comments = TestrunCommentsListGetResponseDataItemRelationshipsChildComments.from_dict(
                _child_comments
            )

        _parent_comment = d.pop("parentComment", UNSET)
        parent_comment: Union[
            Unset,
            TestrunCommentsListGetResponseDataItemRelationshipsParentComment,
        ]
        if isinstance(_parent_comment, Unset):
            parent_comment = UNSET
        else:
            parent_comment = TestrunCommentsListGetResponseDataItemRelationshipsParentComment.from_dict(
                _parent_comment
            )

        _project = d.pop("project", UNSET)
        project: Union[
            Unset, TestrunCommentsListGetResponseDataItemRelationshipsProject
        ]
        if isinstance(_project, Unset):
            project = UNSET
        else:
            project = TestrunCommentsListGetResponseDataItemRelationshipsProject.from_dict(
                _project
            )

        testrun_comments_list_get_response_data_item_relationships_obj = cls(
            author=author,
            child_comments=child_comments,
            parent_comment=parent_comment,
            project=project,
        )

        testrun_comments_list_get_response_data_item_relationships_obj.additional_properties = (
            d
        )
        return testrun_comments_list_get_response_data_item_relationships_obj

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
