# coding: utf-8

"""
    Artifacts API

     Artifacts is an API-based MMO game where you can manage 5 characters to explore, fight, gather resources, craft items and much more.  Website: https://artifactsmmo.com/  Documentation: https://docs.artifactsmmo.com/  OpenAPI Spec: https://api.artifactsmmo.com/openapi.json 

    The version of the OpenAPI document: 1.6
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List
from pyartifactsmmo.models.drop_rate_schema import DropRateSchema
from typing import Optional, Set
from typing_extensions import Self

class MonsterSchema(BaseModel):
    """
    MonsterSchema
    """ # noqa: E501
    name: StrictStr = Field(description="Name of the monster.")
    code: StrictStr = Field(description="The code of the monster. This is the monster's unique identifier (ID).")
    level: StrictInt = Field(description="Monster level.")
    hp: StrictInt = Field(description="Monster hit points.")
    attack_fire: StrictInt = Field(description="Monster fire attack.")
    attack_earth: StrictInt = Field(description="Monster earth attack.")
    attack_water: StrictInt = Field(description="Monster water attack.")
    attack_air: StrictInt = Field(description="Monster air attack.")
    res_fire: StrictInt = Field(description="Monster % fire resistance.")
    res_earth: StrictInt = Field(description="Monster % earth resistance.")
    res_water: StrictInt = Field(description="Monster % water resistance.")
    res_air: StrictInt = Field(description="Monster % air resistance.")
    min_gold: StrictInt = Field(description="Monster minimum gold drop. ")
    max_gold: StrictInt = Field(description="Monster maximum gold drop. ")
    drops: List[DropRateSchema] = Field(description="Monster drops. This is a list of items that the monster drops after killing the monster. ")
    __properties: ClassVar[List[str]] = ["name", "code", "level", "hp", "attack_fire", "attack_earth", "attack_water", "attack_air", "res_fire", "res_earth", "res_water", "res_air", "min_gold", "max_gold", "drops"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of MonsterSchema from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in drops (list)
        _items = []
        if self.drops:
            for _item_drops in self.drops:
                if _item_drops:
                    _items.append(_item_drops.to_dict())
            _dict['drops'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of MonsterSchema from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "code": obj.get("code"),
            "level": obj.get("level"),
            "hp": obj.get("hp"),
            "attack_fire": obj.get("attack_fire"),
            "attack_earth": obj.get("attack_earth"),
            "attack_water": obj.get("attack_water"),
            "attack_air": obj.get("attack_air"),
            "res_fire": obj.get("res_fire"),
            "res_earth": obj.get("res_earth"),
            "res_water": obj.get("res_water"),
            "res_air": obj.get("res_air"),
            "min_gold": obj.get("min_gold"),
            "max_gold": obj.get("max_gold"),
            "drops": [DropRateSchema.from_dict(_item) for _item in obj["drops"]] if obj.get("drops") is not None else None
        })
        return _obj


