# 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, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from openapi_client.models.rich_text_margin import RichTextMargin
from typing import Optional, Set
from typing_extensions import Self

class RichTextStyle(BaseModel):
    """
    RichTextStyle
    """ # noqa: E501
    font_family: Optional[Any] = None
    font_size: Optional[StrictInt] = 16
    font_weight: Optional[StrictInt] = Field(default=400, description="Font weight enumeration.")
    text_color: Optional[StrictStr] = '#000000'
    line_spacing: Optional[Union[StrictFloat, StrictInt]] = 1
    character_spacing: Optional[StrictInt] = 0
    alignment: Optional[StrictStr] = Field(default='left', description="Horizontal alignment enumeration.")
    margin: Optional[RichTextMargin] = None
    __properties: ClassVar[List[str]] = ["font_family", "font_size", "font_weight", "text_color", "line_spacing", "character_spacing", "alignment", "margin"]

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

        if value not in set([100, 200, 300, 400, 500, 600, 700, 800, 900]):
            raise ValueError("must be one of enum values (100, 200, 300, 400, 500, 600, 700, 800, 900)")
        return value

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "font_family": obj.get("font_family"),
            "font_size": obj.get("font_size") if obj.get("font_size") is not None else 16,
            "font_weight": obj.get("font_weight") if obj.get("font_weight") is not None else 400,
            "text_color": obj.get("text_color") if obj.get("text_color") is not None else '#000000',
            "line_spacing": obj.get("line_spacing") if obj.get("line_spacing") is not None else 1,
            "character_spacing": obj.get("character_spacing") if obj.get("character_spacing") is not None else 0,
            "alignment": obj.get("alignment") if obj.get("alignment") is not None else 'left',
            "margin": RichTextMargin.from_dict(obj["margin"]) if obj.get("margin") is not None else None
        })
        return _obj


