# DO NOT EDIT!
# This code was auto generated by the `protoc-gen-pokete-resources-python` plugin,
# part of the pokete project, by <lxgr@protonmail.com>
from typing import TypedDict


class ChatDict(TypedDict):
    q: list[str]
    a: dict[str, "ChatDict"]


class Chat:
    def __init__(self, q: list[str], a: dict[str, "Chat"]):
        self.q: list[str] = q
        self.a: dict[str, "Chat"] = a

    @classmethod
    def from_dict(cls, _d: ChatDict | None) -> "Chat | None":
        if _d is None:
            return None
        return cls(
            q=_d["q"],
            a={i: Chat.from_dict(item) for i, item in _d["a"].items()},
        )

    @staticmethod
    def validate(_d: ChatDict) -> bool:
        return all(
            [
                "q" in _d and all(type(i) is str for i in _d["q"]),
                "a" in _d and all(Chat.validate(item) for _, item in _d["a"].items()),
            ]
        )

    def to_dict(self) -> ChatDict:
        ret: ChatDict = {}

        ret["q"] = self.q
        ret["a"] = {i: Chat.to_dict(item) for i, item in self.a.items()}

        return ret


class NPCDict(TypedDict):
    texts: list[str]
    fn: str | None
    map: str
    x: int
    y: int
    chat: "ChatDict | None"


class NPC:
    def __init__(
        self,
        texts: list[str],
        fn: str | None,
        map: str,
        x: int,
        y: int,
        chat: "Chat | None",
    ):
        self.texts: list[str] = texts
        self.fn: str | None = fn
        self.map: str = map
        self.x: int = x
        self.y: int = y
        self.chat: "Chat | None" = chat

    @classmethod
    def from_dict(cls, _d: NPCDict | None) -> "NPC | None":
        if _d is None:
            return None
        return cls(
            texts=_d["texts"],
            fn=_d.get("fn", None),
            map=_d["map"],
            x=_d["x"],
            y=_d["y"],
            chat=Chat.from_dict(_d.get("chat", None)),
        )

    @staticmethod
    def validate(_d: NPCDict) -> bool:
        return all(
            [
                "texts" in _d and all(type(i) is str for i in _d["texts"]),
                type(_d.get("fn", None)) is str or _d.get("fn", None) is None,
                "map" in _d and type(_d["map"]) is str,
                "x" in _d and type(_d["x"]) is int,
                "y" in _d and type(_d["y"]) is int,
                (
                    True
                    if _d.get("chat", None) is None
                    else Chat.validate(_d.get("chat", None))
                ),
            ]
        )

    def to_dict(self) -> NPCDict:
        ret: NPCDict = {}

        ret["texts"] = self.texts
        if self.fn is not None:
            ret["fn"] = self.fn
        ret["map"] = self.map
        ret["x"] = self.x
        ret["y"] = self.y
        if self.chat is not None:
            ret["chat"] = Chat.to_dict(self.chat)

        return ret
