# 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.background_image import BackgroundImage
from openapi_client.models.banner_styles import BannerStyles
from openapi_client.models.border_style import BorderStyle
from openapi_client.models.close_button_style import CloseButtonStyle
from openapi_client.models.drop_shadow import DropShadow
from openapi_client.models.input_styles import InputStyles
from openapi_client.models.margin import Margin
from openapi_client.models.mobile_overlay import MobileOverlay
from openapi_client.models.padding import Padding
from openapi_client.models.rich_text_styles import RichTextStyles
from typing import Optional, Set
from typing_extensions import Self

class VersionStyles(BaseModel):
    """
    VersionStyles
    """ # noqa: E501
    wrap_content: Optional[StrictBool] = False
    border_styles: Optional[BorderStyle] = None
    close_button: Optional[CloseButtonStyle] = None
    margin: Optional[Margin] = None
    padding: Optional[Padding] = None
    minimum_height: Optional[StrictInt] = 250
    width: Optional[StrictStr] = Field(default='medium', description="Version width enumeration.")
    custom_width: Optional[StrictInt] = None
    background_image: Optional[BackgroundImage] = None
    background_color: Optional[StrictStr] = '#FFFFFF'
    input_styles: Optional[InputStyles] = None
    drop_shadow: Optional[DropShadow] = None
    overlay_color: Optional[StrictStr] = 'rgba(20,20,20,0.6)'
    rich_text_styles: Optional[RichTextStyles] = None
    mobile_overlay: Optional[MobileOverlay] = None
    banner_styles: Optional[BannerStyles] = None
    __properties: ClassVar[List[str]] = ["wrap_content", "border_styles", "close_button", "margin", "padding", "minimum_height", "width", "custom_width", "background_image", "background_color", "input_styles", "drop_shadow", "overlay_color", "rich_text_styles", "mobile_overlay", "banner_styles"]

    @field_validator('width')
    def width_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

    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 VersionStyles 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 border_styles
        if self.border_styles:
            _dict['border_styles'] = self.border_styles.to_dict()
        # override the default output from pydantic by calling `to_dict()` of close_button
        if self.close_button:
            _dict['close_button'] = self.close_button.to_dict()
        # override the default output from pydantic by calling `to_dict()` of margin
        if self.margin:
            _dict['margin'] = self.margin.to_dict()
        # override the default output from pydantic by calling `to_dict()` of padding
        if self.padding:
            _dict['padding'] = self.padding.to_dict()
        # override the default output from pydantic by calling `to_dict()` of background_image
        if self.background_image:
            _dict['background_image'] = self.background_image.to_dict()
        # override the default output from pydantic by calling `to_dict()` of input_styles
        if self.input_styles:
            _dict['input_styles'] = self.input_styles.to_dict()
        # override the default output from pydantic by calling `to_dict()` of drop_shadow
        if self.drop_shadow:
            _dict['drop_shadow'] = self.drop_shadow.to_dict()
        # override the default output from pydantic by calling `to_dict()` of rich_text_styles
        if self.rich_text_styles:
            _dict['rich_text_styles'] = self.rich_text_styles.to_dict()
        # override the default output from pydantic by calling `to_dict()` of mobile_overlay
        if self.mobile_overlay:
            _dict['mobile_overlay'] = self.mobile_overlay.to_dict()
        # override the default output from pydantic by calling `to_dict()` of banner_styles
        if self.banner_styles:
            _dict['banner_styles'] = self.banner_styles.to_dict()
        # set to None if custom_width (nullable) is None
        # and model_fields_set contains the field
        if self.custom_width is None and "custom_width" in self.model_fields_set:
            _dict['custom_width'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "wrap_content": obj.get("wrap_content") if obj.get("wrap_content") is not None else False,
            "border_styles": BorderStyle.from_dict(obj["border_styles"]) if obj.get("border_styles") is not None else None,
            "close_button": CloseButtonStyle.from_dict(obj["close_button"]) if obj.get("close_button") is not None else None,
            "margin": Margin.from_dict(obj["margin"]) if obj.get("margin") is not None else None,
            "padding": Padding.from_dict(obj["padding"]) if obj.get("padding") is not None else None,
            "minimum_height": obj.get("minimum_height") if obj.get("minimum_height") is not None else 250,
            "width": obj.get("width") if obj.get("width") is not None else 'medium',
            "custom_width": obj.get("custom_width"),
            "background_image": BackgroundImage.from_dict(obj["background_image"]) if obj.get("background_image") is not None else None,
            "background_color": obj.get("background_color") if obj.get("background_color") is not None else '#FFFFFF',
            "input_styles": InputStyles.from_dict(obj["input_styles"]) if obj.get("input_styles") is not None else None,
            "drop_shadow": DropShadow.from_dict(obj["drop_shadow"]) if obj.get("drop_shadow") is not None else None,
            "overlay_color": obj.get("overlay_color") if obj.get("overlay_color") is not None else 'rgba(20,20,20,0.6)',
            "rich_text_styles": RichTextStyles.from_dict(obj["rich_text_styles"]) if obj.get("rich_text_styles") is not None else None,
            "mobile_overlay": MobileOverlay.from_dict(obj["mobile_overlay"]) if obj.get("mobile_overlay") is not None else None,
            "banner_styles": BannerStyles.from_dict(obj["banner_styles"]) if obj.get("banner_styles") is not None else None
        })
        return _obj


