# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from pinterestsdk.models.conversion_tag_configs import ConversionTagConfigs
from pinterestsdk.models.enhanced_match_status_type import EnhancedMatchStatusType
from pinterestsdk.models.entity_status import EntityStatus
from typing import Optional, Set
from typing_extensions import Self

class ConversionTagResponse(BaseModel):
    """
    ConversionTagResponse
    """ # noqa: E501
    code_snippet: Optional[StrictStr] = Field(default=None, description="Tag code snippet.")
    configs: Optional[ConversionTagConfigs] = None
    enhanced_match_status: Optional[EnhancedMatchStatusType] = Field(default=None, description="The enhanced match status of the tag")
    id: Optional[StrictStr] = Field(default=None, description="Tag ID.")
    last_fired_time_ms: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Time for the last event fired.")
    name: StrictStr = Field(description="Conversion tag name.")
    version: Optional[StrictStr] = Field(default=None, description="Version number.")
    ad_account_id: StrictStr = Field(description="Ad account ID.")
    status: Optional[EntityStatus] = None
    __properties: ClassVar[List[str]] = ["code_snippet", "configs", "enhanced_match_status", "id", "last_fired_time_ms", "name", "version", "ad_account_id", "status"]

    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 ConversionTagResponse 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "code_snippet",
            "configs",
            "enhanced_match_status",
            "id",
            "last_fired_time_ms",
            "version",
            "ad_account_id",
            "status",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of configs
        if self.configs:
            _dict['configs'] = self.configs.to_dict()
        # set to None if enhanced_match_status (nullable) is None
        # and model_fields_set contains the field
        if self.enhanced_match_status is None and "enhanced_match_status" in self.model_fields_set:
            _dict['enhanced_match_status'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "code_snippet": obj.get("code_snippet"),
            "configs": ConversionTagConfigs.from_dict(obj["configs"]) if obj.get("configs") is not None else None,
            "enhanced_match_status": obj.get("enhanced_match_status"),
            "id": obj.get("id"),
            "last_fired_time_ms": obj.get("last_fired_time_ms"),
            "name": obj.get("name"),
            "version": obj.get("version"),
            "ad_account_id": obj.get("ad_account_id"),
            "status": obj.get("status")
        })
        return _obj


