# coding: utf-8

"""
    webstatus.dev API

    A tool to monitor and track the status of all Web Platform features across dimensions that are related to availability and implementation quality across browsers, and adoption by web developers. 

    The version of the OpenAPI document: 0.1.0
    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 webstatus_openapi.models.baseline_info import BaselineInfo
from webstatus_openapi.models.browser_implementation import BrowserImplementation
from webstatus_openapi.models.browser_usage import BrowserUsage
from webstatus_openapi.models.feature_spec_info import FeatureSpecInfo
from webstatus_openapi.models.feature_wpt_snapshots import FeatureWPTSnapshots
from typing import Optional, Set
from typing_extensions import Self

class Feature(BaseModel):
    """
    Feature
    """ # noqa: E501
    feature_id: StrictStr
    name: StrictStr = Field(description="Short name that is intended to be human friendly. Comes from FeatureData's 'name' field in https://github.com/web-platform-dx/web-features/blob/main/schemas/defs.schema.json ")
    spec: Optional[FeatureSpecInfo] = None
    browser_implementations: Optional[Dict[str, BrowserImplementation]] = Field(default=None, description="Describes the implementation status of the feature. The keys for the object come from https://github.com/web-platform-dx/web-features/blob/8ab08d00b9bdb505af37c435204eb6fe819dfaab/schemas/defs.schema.json#L102-L122 ")
    baseline: Optional[BaselineInfo] = None
    usage: Optional[BrowserUsage] = None
    wpt: Optional[FeatureWPTSnapshots] = None
    __properties: ClassVar[List[str]] = ["feature_id", "name", "spec", "browser_implementations", "baseline", "usage", "wpt"]

    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 Feature 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 spec
        if self.spec:
            _dict['spec'] = self.spec.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in browser_implementations (dict)
        _field_dict = {}
        if self.browser_implementations:
            for _key in self.browser_implementations:
                if self.browser_implementations[_key]:
                    _field_dict[_key] = self.browser_implementations[_key].to_dict()
            _dict['browser_implementations'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of baseline
        if self.baseline:
            _dict['baseline'] = self.baseline.to_dict()
        # override the default output from pydantic by calling `to_dict()` of usage
        if self.usage:
            _dict['usage'] = self.usage.to_dict()
        # override the default output from pydantic by calling `to_dict()` of wpt
        if self.wpt:
            _dict['wpt'] = self.wpt.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "feature_id": obj.get("feature_id"),
            "name": obj.get("name"),
            "spec": FeatureSpecInfo.from_dict(obj["spec"]) if obj.get("spec") is not None else None,
            "browser_implementations": dict(
                (_k, BrowserImplementation.from_dict(_v))
                for _k, _v in obj["browser_implementations"].items()
            )
            if obj.get("browser_implementations") is not None
            else None,
            "baseline": BaselineInfo.from_dict(obj["baseline"]) if obj.get("baseline") is not None else None,
            "usage": BrowserUsage.from_dict(obj["usage"]) if obj.get("usage") is not None else None,
            "wpt": FeatureWPTSnapshots.from_dict(obj["wpt"]) if obj.get("wpt") is not None else None
        })
        return _obj


