# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from pinterestsdk.models.conversion_events_data_inner_custom_data_contents_inner import ConversionEventsDataInnerCustomDataContentsInner
from typing import Optional, Set
from typing_extensions import Self

class ConversionEventsDataInnerCustomData(BaseModel):
    """
    Object containing other custom data.
    """ # noqa: E501
    content_brand: Optional[StrictStr] = Field(default=None, description="The brand of the content associated with the event.")
    content_category: Optional[StrictStr] = Field(default=None, description="The category of the content associated with the event.")
    content_ids: Optional[List[StrictStr]] = Field(default=None, description="List of products IDs. We recommend using this if you are a merchant for PageVisit, AddToCart and Checkouts. For detail, please check <a href=\"https://help.pinterest.com/en/business/article/before-you-get-started-with-catalogs\" target=\"_blank\">here</a> (Install the Pinterest tag section).")
    content_name: Optional[StrictStr] = Field(default=None, description="The name of the page or product associated with the event.")
    contents: Optional[List[ConversionEventsDataInnerCustomDataContentsInner]] = Field(default=None, description="A list of objects containing information about products, such as price and quantity. We recommend using this if you are a merchant for PageVisit, AddToCart and Checkouts. For detail, please check <a href=\"https://help.pinterest.com/en/business/article/before-you-get-started-with-catalogs\" target=\"_blank\">here</a> (Install the Pinterest tag section).")
    currency: Optional[StrictStr] = Field(default=None, description="The ISO-4217 currency code. If not provided, we will default to the advertiser's currency set during account creation. Your campaign performance needs this field to report right ROAS/CPA.")
    external_measurement_id: Optional[StrictStr] = Field(default=None, description="Only use when instructed.")
    external_measurement_vendor_id: Optional[StrictInt] = Field(default=None, description="Only use when instructed.")
    np: Optional[StrictStr] = Field(default=None, description="Named partner. Not required, this is for Pinterest internal use only. Please do not use this unless specifically guided.")
    num_items: Optional[StrictInt] = Field(default=None, description="Total number of products of the event. For example, the total number of items purchased in a checkout event. We recommend using this if you are a merchant for AddToCart and Checkouts. For detail, please check <a href=\"https://help.pinterest.com/en/business/article/before-you-get-started-with-catalogs\" target=\"_blank\">here</a> (Install the Pinterest tag section).")
    opt_out_type: Optional[StrictStr] = Field(default=None, description="Flags for different privacy rights laws to opt out users of sharing personal information. Separate values with commas. See the Help Center article about <a href=\"https://help.pinterest.com/en/business/article/limited-data-processing\" target=\"_blank\">limited data processing</a> and the developer's guide for <a href=\"/docs/track-conversions/track-conversions-in-the-api/#whether-the-user-has-opted-out-of-web-or-offline-conversion-events\" target=\"_blank\">tracking conversion events</a> for help with using this parameter.")
    order_id: Optional[StrictStr] = Field(default=None, description="The order ID. We recommend sending order_id to help us deduplicate events when necessary. This also helps to run other measurement products at Pinterest.")
    predicted_ltv: Optional[StrictStr] = Field(default=None, description="Predicted lifetime value of user associated with the event. Accepted as a string in the request; it will be parsed into a double.")
    search_string: Optional[StrictStr] = Field(default=None, description="The search string related to the user conversion event.")
    value: Optional[StrictStr] = Field(default=None, description="Total value of the event. Accepted as a string in the request; it will be parsed into a double. For example, if there are two items in a checkout event, the value should be the total price. We recommend to use pre-tax, pre-shipping final value.")
    __properties: ClassVar[List[str]] = ["content_brand", "content_category", "content_ids", "content_name", "contents", "currency", "external_measurement_id", "external_measurement_vendor_id", "np", "num_items", "opt_out_type", "order_id", "predicted_ltv", "search_string", "value"]

    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 ConversionEventsDataInnerCustomData 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 contents (list)
        _items = []
        if self.contents:
            for _item_contents in self.contents:
                if _item_contents:
                    _items.append(_item_contents.to_dict())
            _dict['contents'] = _items
        # set to None if content_brand (nullable) is None
        # and model_fields_set contains the field
        if self.content_brand is None and "content_brand" in self.model_fields_set:
            _dict['content_brand'] = None

        # set to None if content_category (nullable) is None
        # and model_fields_set contains the field
        if self.content_category is None and "content_category" in self.model_fields_set:
            _dict['content_category'] = None

        # set to None if content_name (nullable) is None
        # and model_fields_set contains the field
        if self.content_name is None and "content_name" in self.model_fields_set:
            _dict['content_name'] = None

        # set to None if currency (nullable) is None
        # and model_fields_set contains the field
        if self.currency is None and "currency" in self.model_fields_set:
            _dict['currency'] = None

        # set to None if external_measurement_id (nullable) is None
        # and model_fields_set contains the field
        if self.external_measurement_id is None and "external_measurement_id" in self.model_fields_set:
            _dict['external_measurement_id'] = None

        # set to None if external_measurement_vendor_id (nullable) is None
        # and model_fields_set contains the field
        if self.external_measurement_vendor_id is None and "external_measurement_vendor_id" in self.model_fields_set:
            _dict['external_measurement_vendor_id'] = None

        # set to None if np (nullable) is None
        # and model_fields_set contains the field
        if self.np is None and "np" in self.model_fields_set:
            _dict['np'] = None

        # set to None if opt_out_type (nullable) is None
        # and model_fields_set contains the field
        if self.opt_out_type is None and "opt_out_type" in self.model_fields_set:
            _dict['opt_out_type'] = None

        # set to None if order_id (nullable) is None
        # and model_fields_set contains the field
        if self.order_id is None and "order_id" in self.model_fields_set:
            _dict['order_id'] = None

        # set to None if predicted_ltv (nullable) is None
        # and model_fields_set contains the field
        if self.predicted_ltv is None and "predicted_ltv" in self.model_fields_set:
            _dict['predicted_ltv'] = None

        # set to None if search_string (nullable) is None
        # and model_fields_set contains the field
        if self.search_string is None and "search_string" in self.model_fields_set:
            _dict['search_string'] = None

        # set to None if value (nullable) is None
        # and model_fields_set contains the field
        if self.value is None and "value" in self.model_fields_set:
            _dict['value'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "content_brand": obj.get("content_brand"),
            "content_category": obj.get("content_category"),
            "content_ids": obj.get("content_ids"),
            "content_name": obj.get("content_name"),
            "contents": [ConversionEventsDataInnerCustomDataContentsInner.from_dict(_item) for _item in obj["contents"]] if obj.get("contents") is not None else None,
            "currency": obj.get("currency"),
            "external_measurement_id": obj.get("external_measurement_id"),
            "external_measurement_vendor_id": obj.get("external_measurement_vendor_id"),
            "np": obj.get("np"),
            "num_items": obj.get("num_items"),
            "opt_out_type": obj.get("opt_out_type"),
            "order_id": obj.get("order_id"),
            "predicted_ltv": obj.get("predicted_ltv"),
            "search_string": obj.get("search_string"),
            "value": obj.get("value")
        })
        return _obj


