# coding: utf-8

"""
    Pinterest REST API

    Pinterest's REST API

    The version of the OpenAPI document: 5.23.0
    Contact: blah+oapicf@cliffano.com
    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
from typing import Any, ClassVar, Dict, List, Optional
from pinterestsdk.models.quality_component_details import QualityComponentDetails
from typing import Optional, Set
from typing_extensions import Self

class QualityComponents(BaseModel):
    """
    Set of quality components, with each component containing a event coverage and details.
    """ # noqa: E501
    advertiser_external_id: Optional[Dict[str, QualityComponentDetails]] = None
    click_id_epik: Optional[Dict[str, QualityComponentDetails]] = None
    external_event_id: Optional[Dict[str, QualityComponentDetails]] = Field(default=None, description="Dedup components.")
    hashed_email: Optional[Dict[str, QualityComponentDetails]] = Field(default=None, description="User matching identifiers.")
    hashed_maid: Optional[Dict[str, QualityComponentDetails]] = None
    ip_address: Optional[Dict[str, QualityComponentDetails]] = None
    order_id: Optional[Dict[str, QualityComponentDetails]] = None
    order_value: Optional[Dict[str, QualityComponentDetails]] = None
    product_id: Optional[Dict[str, QualityComponentDetails]] = Field(default=None, description="Product/event metadata.")
    source_url: Optional[Dict[str, QualityComponentDetails]] = None
    user_agent: Optional[Dict[str, QualityComponentDetails]] = None
    __properties: ClassVar[List[str]] = ["advertiser_external_id", "click_id_epik", "external_event_id", "hashed_email", "hashed_maid", "ip_address", "order_id", "order_value", "product_id", "source_url", "user_agent"]

    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 QualityComponents 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 value in advertiser_external_id (dict)
        _field_dict = {}
        if self.advertiser_external_id:
            for _key_advertiser_external_id in self.advertiser_external_id:
                if self.advertiser_external_id[_key_advertiser_external_id]:
                    _field_dict[_key_advertiser_external_id] = self.advertiser_external_id[_key_advertiser_external_id].to_dict()
            _dict['advertiser_external_id'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in click_id_epik (dict)
        _field_dict = {}
        if self.click_id_epik:
            for _key_click_id_epik in self.click_id_epik:
                if self.click_id_epik[_key_click_id_epik]:
                    _field_dict[_key_click_id_epik] = self.click_id_epik[_key_click_id_epik].to_dict()
            _dict['click_id_epik'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in external_event_id (dict)
        _field_dict = {}
        if self.external_event_id:
            for _key_external_event_id in self.external_event_id:
                if self.external_event_id[_key_external_event_id]:
                    _field_dict[_key_external_event_id] = self.external_event_id[_key_external_event_id].to_dict()
            _dict['external_event_id'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in hashed_email (dict)
        _field_dict = {}
        if self.hashed_email:
            for _key_hashed_email in self.hashed_email:
                if self.hashed_email[_key_hashed_email]:
                    _field_dict[_key_hashed_email] = self.hashed_email[_key_hashed_email].to_dict()
            _dict['hashed_email'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in hashed_maid (dict)
        _field_dict = {}
        if self.hashed_maid:
            for _key_hashed_maid in self.hashed_maid:
                if self.hashed_maid[_key_hashed_maid]:
                    _field_dict[_key_hashed_maid] = self.hashed_maid[_key_hashed_maid].to_dict()
            _dict['hashed_maid'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in ip_address (dict)
        _field_dict = {}
        if self.ip_address:
            for _key_ip_address in self.ip_address:
                if self.ip_address[_key_ip_address]:
                    _field_dict[_key_ip_address] = self.ip_address[_key_ip_address].to_dict()
            _dict['ip_address'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in order_id (dict)
        _field_dict = {}
        if self.order_id:
            for _key_order_id in self.order_id:
                if self.order_id[_key_order_id]:
                    _field_dict[_key_order_id] = self.order_id[_key_order_id].to_dict()
            _dict['order_id'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in order_value (dict)
        _field_dict = {}
        if self.order_value:
            for _key_order_value in self.order_value:
                if self.order_value[_key_order_value]:
                    _field_dict[_key_order_value] = self.order_value[_key_order_value].to_dict()
            _dict['order_value'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in product_id (dict)
        _field_dict = {}
        if self.product_id:
            for _key_product_id in self.product_id:
                if self.product_id[_key_product_id]:
                    _field_dict[_key_product_id] = self.product_id[_key_product_id].to_dict()
            _dict['product_id'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in source_url (dict)
        _field_dict = {}
        if self.source_url:
            for _key_source_url in self.source_url:
                if self.source_url[_key_source_url]:
                    _field_dict[_key_source_url] = self.source_url[_key_source_url].to_dict()
            _dict['source_url'] = _field_dict
        # override the default output from pydantic by calling `to_dict()` of each value in user_agent (dict)
        _field_dict = {}
        if self.user_agent:
            for _key_user_agent in self.user_agent:
                if self.user_agent[_key_user_agent]:
                    _field_dict[_key_user_agent] = self.user_agent[_key_user_agent].to_dict()
            _dict['user_agent'] = _field_dict
        return _dict

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

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

        _obj = cls.model_validate({
            "advertiser_external_id": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["advertiser_external_id"].items()
            )
            if obj.get("advertiser_external_id") is not None
            else None,
            "click_id_epik": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["click_id_epik"].items()
            )
            if obj.get("click_id_epik") is not None
            else None,
            "external_event_id": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["external_event_id"].items()
            )
            if obj.get("external_event_id") is not None
            else None,
            "hashed_email": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["hashed_email"].items()
            )
            if obj.get("hashed_email") is not None
            else None,
            "hashed_maid": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["hashed_maid"].items()
            )
            if obj.get("hashed_maid") is not None
            else None,
            "ip_address": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["ip_address"].items()
            )
            if obj.get("ip_address") is not None
            else None,
            "order_id": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["order_id"].items()
            )
            if obj.get("order_id") is not None
            else None,
            "order_value": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["order_value"].items()
            )
            if obj.get("order_value") is not None
            else None,
            "product_id": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["product_id"].items()
            )
            if obj.get("product_id") is not None
            else None,
            "source_url": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["source_url"].items()
            )
            if obj.get("source_url") is not None
            else None,
            "user_agent": dict(
                (_k, QualityComponentDetails.from_dict(_v))
                for _k, _v in obj["user_agent"].items()
            )
            if obj.get("user_agent") is not None
            else None
        })
        return _obj


