# 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.currency import Currency
from pinterestsdk.models.line_item import LineItem
from typing import Optional, Set
from typing_extensions import Self

class EventData(BaseModel):
    """
        Optional for VISITOR `audience_type`.     With the Pinterest tag, you can use event data to capture event details from your website.     This object lists all the available predefined event data fields in the Pinterest tag.     You can include these event data fields as part of a VISITOR audience’s `rule`; however, you **must** specify an `event` for the `event_data` fields to be evaluated.     Besides what’s listed, you can also create your own set of `event_data` fields and define their usages or purposes according to your website needs.     However, the benefit of using the predefined event data fields is that we can provide various metrics based on those fields' data.     Examples per `event` type:     `pagevisit`     \"event_data\": { \"page_name\": \"My online store 123 | view items | shoe\" }     `signup`     \"event_data\": { \"lead_type\": \"New release promotion\" }     `checkout`     \"event_data\": { \"value\": 116, \"order_quantity\": 2, \"currency\": \"USD\", \"line_items\": [ { \"product_name\": \"Pillows (Set of 2)\", \"product_id\": \"11\", \"product_price\": 48, \"product_quantity\": 1 }, { \"product_name\": \"Pillows, Large (Set of 2)\", \"product_id\": \"15\", \"product_price\": 68, \"product_quantity\": 1 } ] }     `addtocart`     \"event_data\": { \"value\": 499, \"order_quantity\": 1, \"currency\": \"USD\", \"line_items\": [ { \"product_name\": \"Red leather boots\", \"product_id\": \"3486\", \"product_category\": \"shoe\", \"product_variant_id\": \"JB11103000\", \"product_price\": 499, \"product_quantity\": \"1\", \"product_brand\": \"My brand\" }]}     `watchvideo`     \"event_data\": { \"video_title\": \"My Product Video 01\" }     `lead`     \"event_data\": { \"lead_type\": \"Newsletter\" }
    """ # noqa: E501
    currency: Optional[Currency] = Field(default=None, description="Currency. For example, 'USD'.")
    lead_type: Optional[StrictStr] = Field(default=None, description="Promotion code. For example, 'Newsletter'.")
    line_items: Optional[LineItem] = None
    order_id: Optional[StrictStr] = Field(default=None, description="Order ID. For example, 'X-151481'.")
    order_quantity: Optional[StrictInt] = Field(default=None, description="Order quantity. For example, 1.")
    page_name: Optional[StrictStr] = Field(default=None, description="Page name. For example, 'Our Favorite Pins on Pinterest'.")
    promo_code: Optional[StrictStr] = Field(default=None, description="Promotion code. For example, 'WINTER10'.")
    var_property: Optional[StrictStr] = Field(default=None, description="Property. For example, 'Athleta'.", alias="property")
    search_query: Optional[StrictStr] = Field(default=None, description="Search query string. For example, 'boots'.")
    value: Optional[StrictStr] = Field(default=None, description="Product value. For example, '199.98'.")
    video_title: Optional[StrictStr] = Field(default=None, description="Video title. For example, 'How to style your Parker Boots'.")
    __properties: ClassVar[List[str]] = ["currency", "lead_type", "line_items", "order_id", "order_quantity", "page_name", "promo_code", "property", "search_query", "value", "video_title"]

    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 EventData 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 line_items
        if self.line_items:
            _dict['line_items'] = self.line_items.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "currency": obj.get("currency"),
            "lead_type": obj.get("lead_type"),
            "line_items": LineItem.from_dict(obj["line_items"]) if obj.get("line_items") is not None else None,
            "order_id": obj.get("order_id"),
            "order_quantity": obj.get("order_quantity"),
            "page_name": obj.get("page_name"),
            "promo_code": obj.get("promo_code"),
            "property": obj.get("property"),
            "search_query": obj.get("search_query"),
            "value": obj.get("value"),
            "video_title": obj.get("video_title")
        })
        return _obj


