# coding: utf-8

"""
    Klaviyo API

    The Klaviyo REST API. Please visit https://developers.klaviyo.com for more details.

    Contact: developers@klaviyo.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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.teaser_styles import TeaserStyles
from typing import Optional, Set
from typing_extensions import Self

class Teaser(BaseModel):
    """
    Teaser
    """ # noqa: E501
    id: Optional[StrictStr] = None
    content: StrictStr
    display_order: Optional[StrictStr] = Field(default='after', description="Teaser display order enumeration.")
    teaser_type: Optional[StrictStr] = Field(default='rectangle', description="Teaser display order enumeration.")
    location: Optional[StrictStr] = Field(default='bottom_left', description="Display location enumeration.")
    size: Optional[StrictStr] = Field(default='small', description="Teaser size enumeration.")
    custom_size: Optional[StrictInt] = None
    styles: Optional[TeaserStyles] = None
    close_button: Optional[StrictBool] = True
    device_type: Optional[StrictStr] = Field(default='both', description="Enumeration for mobile and desktop.")
    __properties: ClassVar[List[str]] = ["id", "content", "display_order", "teaser_type", "location", "size", "custom_size", "styles", "close_button", "device_type"]

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

        if value not in set(['after', 'before', 'before_and_after']):
            raise ValueError("must be one of enum values ('after', 'before', 'before_and_after')")
        return value

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

        if value not in set(['circle', 'corner', 'rectangle']):
            raise ValueError("must be one of enum values ('circle', 'corner', 'rectangle')")
        return value

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

        if value not in set(['bottom_center', 'bottom_left', 'bottom_right', 'center_left', 'center_right', 'top_center', 'top_left', 'top_right']):
            raise ValueError("must be one of enum values ('bottom_center', 'bottom_left', 'bottom_right', 'center_left', 'center_right', 'top_center', 'top_left', 'top_right')")
        return value

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

        if value not in set(['custom', 'large', 'medium', 'small']):
            raise ValueError("must be one of enum values ('custom', 'large', 'medium', 'small')")
        return value

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "content": obj.get("content"),
            "display_order": obj.get("display_order") if obj.get("display_order") is not None else 'after',
            "teaser_type": obj.get("teaser_type") if obj.get("teaser_type") is not None else 'rectangle',
            "location": obj.get("location") if obj.get("location") is not None else 'bottom_left',
            "size": obj.get("size") if obj.get("size") is not None else 'small',
            "custom_size": obj.get("custom_size"),
            "styles": TeaserStyles.from_dict(obj["styles"]) if obj.get("styles") is not None else None,
            "close_button": obj.get("close_button") if obj.get("close_button") is not None else True,
            "device_type": obj.get("device_type") if obj.get("device_type") is not None else 'both'
        })
        return _obj


