# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.integration_log_client_error import IntegrationLogClientError
from pinterestsdk.models.integration_log_client_request import IntegrationLogClientRequest
from typing import Optional, Set
from typing_extensions import Self

class IntegrationLog(BaseModel):
    """
    Schema for log sent from an integration application.
    """ # noqa: E501
    advertiser_id: Optional[Annotated[str, Field(strict=True, max_length=128)]] = None
    app_version_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="Version number of the integration application.")
    client_timestamp: StrictInt = Field(description="Timestamp in milliseconds of when the log was executed at the client.")
    error: Optional[IntegrationLogClientError] = None
    event_type: StrictStr = Field(description="Log event type")
    external_business_id: Optional[Annotated[str, Field(strict=True, max_length=2048)]] = None
    feed_profile_id: Optional[Annotated[str, Field(strict=True, max_length=128)]] = None
    log_level: StrictStr = Field(description="Log level type")
    merchant_id: Optional[Annotated[str, Field(strict=True, max_length=128)]] = None
    message: Optional[Annotated[str, Field(strict=True, max_length=8192)]] = Field(default=None, description="Explanation of the event that occured.")
    platform_version_number: Optional[Annotated[str, Field(strict=True, max_length=20)]] = Field(default=None, description="Version number of the platform the integration application is running on.")
    request: Optional[IntegrationLogClientRequest] = None
    tag_id: Optional[Annotated[str, Field(strict=True, max_length=128)]] = None
    __properties: ClassVar[List[str]] = ["advertiser_id", "app_version_number", "client_timestamp", "error", "event_type", "external_business_id", "feed_profile_id", "log_level", "merchant_id", "message", "platform_version_number", "request", "tag_id"]

    @field_validator('event_type')
    def event_type_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['APP', 'API']):
            raise ValueError("must be one of enum values ('APP', 'API')")
        return value

    @field_validator('log_level')
    def log_level_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['INFO', 'WARN', 'ERROR']):
            raise ValueError("must be one of enum values ('INFO', 'WARN', 'ERROR')")
        return 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 IntegrationLog 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 error
        if self.error:
            _dict['error'] = self.error.to_dict()
        # override the default output from pydantic by calling `to_dict()` of request
        if self.request:
            _dict['request'] = self.request.to_dict()
        # set to None if advertiser_id (nullable) is None
        # and model_fields_set contains the field
        if self.advertiser_id is None and "advertiser_id" in self.model_fields_set:
            _dict['advertiser_id'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "advertiser_id": obj.get("advertiser_id"),
            "app_version_number": obj.get("app_version_number"),
            "client_timestamp": obj.get("client_timestamp"),
            "error": IntegrationLogClientError.from_dict(obj["error"]) if obj.get("error") is not None else None,
            "event_type": obj.get("event_type"),
            "external_business_id": obj.get("external_business_id"),
            "feed_profile_id": obj.get("feed_profile_id"),
            "log_level": obj.get("log_level"),
            "merchant_id": obj.get("merchant_id"),
            "message": obj.get("message"),
            "platform_version_number": obj.get("platform_version_number"),
            "request": IntegrationLogClientRequest.from_dict(obj["request"]) if obj.get("request") is not None else None,
            "tag_id": obj.get("tag_id")
        })
        return _obj


