from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

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

from ..types import UNSET, Unset

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


@_attrs_define
class TypesCommunityPost:
    """
    Attributes:
        field_id (str | Unset):
        author (str | Unset):
        content (str | Unset):
        created_at (str | Unset):
        deleted_at (str | Unset):
        edited_at (str | Unset):
        likes (list[str] | Unset):
        modified_at (str | Unset):
        thread (str | Unset):
        topic (str | Unset):
    """

    field_id: str | Unset = UNSET
    author: str | Unset = UNSET
    content: str | Unset = UNSET
    created_at: str | Unset = UNSET
    deleted_at: str | Unset = UNSET
    edited_at: str | Unset = UNSET
    likes: list[str] | Unset = UNSET
    modified_at: str | Unset = UNSET
    thread: str | Unset = UNSET
    topic: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        field_id = self.field_id

        author = self.author

        content = self.content

        created_at = self.created_at

        deleted_at = self.deleted_at

        edited_at = self.edited_at

        likes: list[str] | Unset = UNSET
        if not isinstance(self.likes, Unset):
            likes = self.likes

        modified_at = self.modified_at

        thread = self.thread

        topic = self.topic

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if field_id is not UNSET:
            field_dict["_id"] = field_id
        if author is not UNSET:
            field_dict["author"] = author
        if content is not UNSET:
            field_dict["content"] = content
        if created_at is not UNSET:
            field_dict["created_at"] = created_at
        if deleted_at is not UNSET:
            field_dict["deleted_at"] = deleted_at
        if edited_at is not UNSET:
            field_dict["edited_at"] = edited_at
        if likes is not UNSET:
            field_dict["likes"] = likes
        if modified_at is not UNSET:
            field_dict["modified_at"] = modified_at
        if thread is not UNSET:
            field_dict["thread"] = thread
        if topic is not UNSET:
            field_dict["topic"] = topic

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        field_id = d.pop("_id", UNSET)

        author = d.pop("author", UNSET)

        content = d.pop("content", UNSET)

        created_at = d.pop("created_at", UNSET)

        deleted_at = d.pop("deleted_at", UNSET)

        edited_at = d.pop("edited_at", UNSET)

        likes = cast(list[str], d.pop("likes", UNSET))

        modified_at = d.pop("modified_at", UNSET)

        thread = d.pop("thread", UNSET)

        topic = d.pop("topic", UNSET)

        types_community_post = cls(
            field_id=field_id,
            author=author,
            content=content,
            created_at=created_at,
            deleted_at=deleted_at,
            edited_at=edited_at,
            likes=likes,
            modified_at=modified_at,
            thread=thread,
            topic=topic,
        )

        types_community_post.additional_properties = d
        return types_community_post

    @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
