# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pinterestsdk.models.optimization_goal_metadata_conversion_tag_v3_goal_metadata_attribution_windows import OptimizationGoalMetadataConversionTagV3GoalMetadataAttributionWindows
from typing import Optional, Set
from typing_extensions import Self

class OptimizationGoalMetadataConversionTagV3GoalMetadata(BaseModel):
    """
    OptimizationGoalMetadataConversionTagV3GoalMetadata
    """ # noqa: E501
    attribution_windows: Optional[OptimizationGoalMetadataConversionTagV3GoalMetadataAttributionWindows] = None
    conversion_event: Optional[StrictStr] = None
    conversion_tag_id: Optional[Annotated[str, Field(strict=True)]] = None
    cpa_goal_value_in_micro_currency: Optional[Annotated[str, Field(strict=True)]] = None
    is_roas_optimized: Optional[StrictBool] = Field(default=None, description="Pinterest Performance+ ROAS bidding. When enabled, Pinterest will optimize for conversion value instead of conversion volume. Only supported when `conversion_event` is set to `\"CHECKOUT\"` and `bid_strategy_type` is set to `\"AUTOMATIC_BID\"`. <br>This parameter is not enabled for all advertisers. <a href=\"https://developers.pinterest.com/docs/getting-started/using-beta-and-restricted-features/\">Learn more</a>.")
    learning_mode_type: Optional[StrictStr] = Field(default=None, description="Conversion learning model type")
    reporting_event: Optional[StrictStr] = Field(default=None, description="Event name for custom or standard events mapped to an oCPM model")
    __properties: ClassVar[List[str]] = ["attribution_windows", "conversion_event", "conversion_tag_id", "cpa_goal_value_in_micro_currency", "is_roas_optimized", "learning_mode_type", "reporting_event"]

    @field_validator('conversion_event')
    def conversion_event_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['PAGE_VISIT', 'SIGNUP', 'CHECKOUT', 'CUSTOM', 'VIEW_CATEGORY', 'SEARCH', 'ADD_TO_CART', 'WATCH_VIDEO', 'LEAD', 'APP_INSTALL']):
            raise ValueError("must be one of enum values ('PAGE_VISIT', 'SIGNUP', 'CHECKOUT', 'CUSTOM', 'VIEW_CATEGORY', 'SEARCH', 'ADD_TO_CART', 'WATCH_VIDEO', 'LEAD', 'APP_INSTALL')")
        return value

    @field_validator('conversion_tag_id')
    def conversion_tag_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[0-9]+$", value):
            raise ValueError(r"must validate the regular expression /^[0-9]+$/")
        return value

    @field_validator('cpa_goal_value_in_micro_currency')
    def cpa_goal_value_in_micro_currency_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[0-9]+$", value):
            raise ValueError(r"must validate the regular expression /^[0-9]+$/")
        return value

    @field_validator('learning_mode_type')
    def learning_mode_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['NOT_ACTIVE', 'ACTIVE']):
            raise ValueError("must be one of enum values ('NOT_ACTIVE', 'ACTIVE')")
        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 OptimizationGoalMetadataConversionTagV3GoalMetadata 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 attribution_windows
        if self.attribution_windows:
            _dict['attribution_windows'] = self.attribution_windows.to_dict()
        # set to None if is_roas_optimized (nullable) is None
        # and model_fields_set contains the field
        if self.is_roas_optimized is None and "is_roas_optimized" in self.model_fields_set:
            _dict['is_roas_optimized'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "attribution_windows": OptimizationGoalMetadataConversionTagV3GoalMetadataAttributionWindows.from_dict(obj["attribution_windows"]) if obj.get("attribution_windows") is not None else None,
            "conversion_event": obj.get("conversion_event"),
            "conversion_tag_id": obj.get("conversion_tag_id"),
            "cpa_goal_value_in_micro_currency": obj.get("cpa_goal_value_in_micro_currency"),
            "is_roas_optimized": obj.get("is_roas_optimized"),
            "learning_mode_type": obj.get("learning_mode_type"),
            "reporting_event": obj.get("reporting_event")
        })
        return _obj


