# 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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pyartifactsmmo.models.craft_schema import CraftSchema
from pyartifactsmmo.models.item_effect_schema import ItemEffectSchema
from typing import Optional, Set
from typing_extensions import Self

class ItemSchema(BaseModel):
    """
    ItemSchema
    """ # noqa: E501
    name: StrictStr = Field(description="Item name.")
    code: StrictStr = Field(description="Item code. This is the item's unique identifier (ID).")
    level: Annotated[int, Field(strict=True, ge=1)] = Field(description="Item level.")
    type: StrictStr = Field(description="Item type.")
    subtype: StrictStr = Field(description="Item subtype.")
    description: StrictStr = Field(description="Item description.")
    effects: Optional[List[ItemEffectSchema]] = Field(default=None, description="List of object effects. For equipment, it will include item stats.")
    craft: Optional[CraftSchema] = None
    __properties: ClassVar[List[str]] = ["name", "code", "level", "type", "subtype", "description", "effects", "craft"]

    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 ItemSchema 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 effects (list)
        _items = []
        if self.effects:
            for _item_effects in self.effects:
                if _item_effects:
                    _items.append(_item_effects.to_dict())
            _dict['effects'] = _items
        # override the default output from pydantic by calling `to_dict()` of craft
        if self.craft:
            _dict['craft'] = self.craft.to_dict()
        # set to None if craft (nullable) is None
        # and model_fields_set contains the field
        if self.craft is None and "craft" in self.model_fields_set:
            _dict['craft'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ItemSchema 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"),
            "type": obj.get("type"),
            "subtype": obj.get("subtype"),
            "description": obj.get("description"),
            "effects": [ItemEffectSchema.from_dict(_item) for _item in obj["effects"]] if obj.get("effects") is not None else None,
            "craft": CraftSchema.from_dict(obj["craft"]) if obj.get("craft") is not None else None
        })
        return _obj


