# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from pinterestsdk.models.conversion_event_app_info import ConversionEventAppInfo
from pinterestsdk.models.conversion_event_device_info import ConversionEventDeviceInfo
from pinterestsdk.models.conversion_events_data_inner_custom_data import ConversionEventsDataInnerCustomData
from pinterestsdk.models.conversion_events_user_data import ConversionEventsUserData
from typing import Optional, Set
from typing_extensions import Self

class ConversionEventsDataInner(BaseModel):
    """
    ConversionEventsDataInner
    """ # noqa: E501
    action_source: StrictStr = Field(description="<p>The source indicating where the conversion event occurred.</p> - `app_android` - `app_ios` - `web` - `offline`")
    app_id: Optional[StrictStr] = Field(default=None, description="The app store app ID.")
    app_info: Optional[ConversionEventAppInfo] = None
    app_name: Optional[StrictStr] = Field(default=None, description="Name of the app.")
    app_version: Optional[StrictStr] = Field(default=None, description="Version of the app.")
    custom_data: Optional[ConversionEventsDataInnerCustomData] = None
    device_brand: Optional[StrictStr] = Field(default=None, description="Brand of the user device.")
    device_carrier: Optional[StrictStr] = Field(default=None, description="User device's mobile carrier.")
    device_info: Optional[ConversionEventDeviceInfo] = None
    device_model: Optional[StrictStr] = Field(default=None, description="Model of the user device.")
    device_type: Optional[StrictStr] = Field(default=None, description="Type of the user device.")
    event_id: StrictStr = Field(description="A unique id string that identifies this event and can be used for deduping between events ingested via both the conversion API and Pinterest tracking. Without this, event's data is likely to be double counted and will cause report metric inflation. Third-party vendors make sure this field is updated on both Pinterest tag and Conversions API side before rolling out template for Conversions API.")
    event_name: StrictStr = Field(description="<p>The type of the user event. Please use the right event_name; otherwise the event will not be accepted and show up correctly in reports.</p>  - `add_payment_info` - `add_to_cart` - `add_to_wishlist` - `app_install` - `checkout` - `custom` - `initiate_checkout` - `lead` - `page_visit` - `search` - `signup` - `subscribe` - `view_category` - `view_content` - `watch_video`")
    event_source_url: Optional[StrictStr] = Field(default=None, description="URL of the web conversion event.")
    event_time: StrictInt = Field(description="The time when the event happened. Unix timestamp in seconds.")
    language: Optional[StrictStr] = Field(default=None, description="Two-character ISO-639-1 language code indicating the user's language.")
    opt_out: Optional[StrictBool] = Field(default=None, description="When action_source is web or offline, it defines whether the user has opted out of tracking for web conversion events. While when action_source is app_android or app_ios, it defines whether the user has enabled Limit Ad Tracking on their iOS device, or opted out of Ads Personalization on their Android device.")
    os_version: Optional[StrictStr] = Field(default=None, description="Version of the device operating system.")
    partner_name: Optional[StrictStr] = Field(default=None, description="The third party partner name responsible to send the event to Conversions API on behalf of the advertiser. The naming convention is \"ss-partnername\" lowercase. E.g ‘ss-shopify’")
    user_data: ConversionEventsUserData
    wifi: Optional[StrictBool] = Field(default=None, description="Whether the event occurred when the user device was connected to wifi.")
    __properties: ClassVar[List[str]] = ["action_source", "app_id", "app_info", "app_name", "app_version", "custom_data", "device_brand", "device_carrier", "device_info", "device_model", "device_type", "event_id", "event_name", "event_source_url", "event_time", "language", "opt_out", "os_version", "partner_name", "user_data", "wifi"]

    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 ConversionEventsDataInner 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 app_info
        if self.app_info:
            _dict['app_info'] = self.app_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of custom_data
        if self.custom_data:
            _dict['custom_data'] = self.custom_data.to_dict()
        # override the default output from pydantic by calling `to_dict()` of device_info
        if self.device_info:
            _dict['device_info'] = self.device_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user_data
        if self.user_data:
            _dict['user_data'] = self.user_data.to_dict()
        # set to None if app_id (nullable) is None
        # and model_fields_set contains the field
        if self.app_id is None and "app_id" in self.model_fields_set:
            _dict['app_id'] = None

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "action_source": obj.get("action_source"),
            "app_id": obj.get("app_id"),
            "app_info": ConversionEventAppInfo.from_dict(obj["app_info"]) if obj.get("app_info") is not None else None,
            "app_name": obj.get("app_name"),
            "app_version": obj.get("app_version"),
            "custom_data": ConversionEventsDataInnerCustomData.from_dict(obj["custom_data"]) if obj.get("custom_data") is not None else None,
            "device_brand": obj.get("device_brand"),
            "device_carrier": obj.get("device_carrier"),
            "device_info": ConversionEventDeviceInfo.from_dict(obj["device_info"]) if obj.get("device_info") is not None else None,
            "device_model": obj.get("device_model"),
            "device_type": obj.get("device_type"),
            "event_id": obj.get("event_id"),
            "event_name": obj.get("event_name"),
            "event_source_url": obj.get("event_source_url"),
            "event_time": obj.get("event_time"),
            "language": obj.get("language"),
            "opt_out": obj.get("opt_out"),
            "os_version": obj.get("os_version"),
            "partner_name": obj.get("partner_name"),
            "user_data": ConversionEventsUserData.from_dict(obj["user_data"]) if obj.get("user_data") is not None else None,
            "wifi": obj.get("wifi")
        })
        return _obj


