# 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 AttackDict(TypedDict):
    name: str
    factor: float
    action: str | None
    world_action: str
    move: list[str]
    miss_chance: float
    min_lvl: int
    desc: str
    types: list[str]
    effect: str | None
    is_generic: bool
    ap: int


class Attack:
    def __init__(
        self,
        name: str,
        factor: float,
        action: str | None,
        world_action: str,
        move: list[str],
        miss_chance: float,
        min_lvl: int,
        desc: str,
        types: list[str],
        effect: str | None,
        is_generic: bool,
        ap: int,
    ):
        self.name: str = name
        self.factor: float = factor
        self.action: str | None = action
        self.world_action: str = world_action
        self.move: list[str] = move
        self.miss_chance: float = miss_chance
        self.min_lvl: int = min_lvl
        self.desc: str = desc
        self.types: list[str] = types
        self.effect: str | None = effect
        self.is_generic: bool = is_generic
        self.ap: int = ap

    @classmethod
    def from_dict(cls, _d: AttackDict | None) -> "Attack | None":
        if _d is None:
            return None
        return cls(
            name=_d["name"],
            factor=_d["factor"],
            action=_d.get("action", None),
            world_action=_d["world_action"],
            move=_d["move"],
            miss_chance=_d["miss_chance"],
            min_lvl=_d["min_lvl"],
            desc=_d["desc"],
            types=_d["types"],
            effect=_d.get("effect", None),
            is_generic=_d["is_generic"],
            ap=_d["ap"],
        )

    @staticmethod
    def validate(_d: AttackDict) -> bool:
        return all(
            [
                "name" in _d and type(_d["name"]) is str,
                "factor" in _d
                and type(_d["factor"]) is float
                or type(_d["factor"]) is int,
                type(_d.get("action", None)) is str or _d.get("action", None) is None,
                "world_action" in _d and type(_d["world_action"]) is str,
                "move" in _d and all(type(i) is str for i in _d["move"]),
                "miss_chance" in _d
                and type(_d["miss_chance"]) is float
                or type(_d["miss_chance"]) is int,
                "min_lvl" in _d and type(_d["min_lvl"]) is int,
                "desc" in _d and type(_d["desc"]) is str,
                "types" in _d and all(type(i) is str for i in _d["types"]),
                type(_d.get("effect", None)) is str or _d.get("effect", None) is None,
                "is_generic" in _d and type(_d["is_generic"]) is bool,
                "ap" in _d and type(_d["ap"]) is int,
            ]
        )

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

        ret["name"] = self.name
        ret["factor"] = self.factor
        if self.action is not None:
            ret["action"] = self.action
        ret["world_action"] = self.world_action
        ret["move"] = self.move
        ret["miss_chance"] = self.miss_chance
        ret["min_lvl"] = self.min_lvl
        ret["desc"] = self.desc
        ret["types"] = self.types
        if self.effect is not None:
            ret["effect"] = self.effect
        ret["is_generic"] = self.is_generic
        ret["ap"] = self.ap

        return ret
