from typing import Optional, override
from flut._flut.engine import FlutImmutableObject
from flut._flut.runtime import _flut_unpack_optional_field
from flut.dart.ui import FontWeight


class TextStyle(FlutImmutableObject):
    def __init__(
        self,
        *,
        color=None,
        fontSize: Optional[float] = None,
        fontWeight: Optional[FontWeight] = None,
        height: Optional[float] = None,
        fontFamily: Optional[str] = None,
    ):
        super().__init__("TextStyle")
        self.color = color
        self.fontSize = fontSize
        self.fontWeight = fontWeight
        self.height = height
        self.fontFamily = fontFamily

    @override
    def _flut_pack(self) -> dict:
        result = self._flut_base_props()
        if self.fontSize is not None:
            result["fontSize"] = self.fontSize
        if self.fontWeight is not None:
            result["fontWeight"] = self.fontWeight._flut_pack()
        if self.color is not None:
            result["color"] = self.color._flut_pack()
        if self.fontFamily is not None:
            result["fontFamily"] = self.fontFamily
        if self.height is not None:
            result["height"] = self.height
        return result

    @staticmethod
    def _flut_unpack(data: dict) -> "TextStyle":
        return TextStyle(
            color=_flut_unpack_optional_field(data, "color"),
            fontSize=_flut_unpack_optional_field(data, "fontSize"),
            fontWeight=_flut_unpack_optional_field(data, "fontWeight"),
            height=_flut_unpack_optional_field(data, "height"),
            fontFamily=_flut_unpack_optional_field(data, "fontFamily"),
        )
