# coding: utf-8

"""
    FastAPI

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.0
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from instalabel.client.models.class_information import ClassInformation
from typing import Optional, Set
from typing_extensions import Self

class BBoxAnnotation(BaseModel):
    """
    Represents a bounding box annotation, extending the base annotation with specific fields for bounding boxes.  Attributes:     x (int): The x-coordinate of the top-left corner of the bounding box.     y (int): The y-coordinate of the top-left corner of the bounding box.     width (int): The width of the bounding box.     height (int): The height of the bounding box.     fill (str): The fill hexadecimal color for the bounding box.     stroke (str): The stroke hexadecimal color for the bounding box.
    """ # noqa: E501
    id: StrictStr = Field(description="A unique identifier for the annotation.")
    class_id: StrictStr = Field(description="The identifier of the class associated with the annotation.", alias="classId")
    class_name: StrictStr = Field(description="The name of the class associated with the annotation.", alias="className")
    color: StrictStr = Field(description="The color used for the annotation.")
    type: Optional[StrictStr] = Field(default='boundingBox', description="The type of annotation ('boundingBox').")
    class_attributes_selections: Optional[Dict[str, List[StrictStr]]] = Field(default=None, description="A dictionary mapping attribute IDs to lists of selected values.", alias="classAttributesSelections")
    class_information: ClassInformation = Field(description="Metadata about the class associated with the annotation.", alias="classInformation")
    x: StrictInt = Field(description="The x-coordinate of the top-left corner of the bounding box.")
    y: StrictInt = Field(description="The y-coordinate of the top-left corner of the bounding box.")
    width: StrictInt = Field(description="The width of the bounding box.")
    height: StrictInt = Field(description="The height of the bounding box.")
    fill: StrictStr = Field(description="The fill color for the bounding box.")
    stroke: StrictStr = Field(description="The stroke color for the bounding box.")
    __properties: ClassVar[List[str]] = ["id", "classId", "className", "color", "type", "classAttributesSelections", "classInformation", "x", "y", "width", "height", "fill", "stroke"]

    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 BBoxAnnotation 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 class_information
        if self.class_information:
            _dict['classInformation'] = self.class_information.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BBoxAnnotation 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"),
            "classId": obj.get("classId"),
            "className": obj.get("className"),
            "color": obj.get("color"),
            "type": obj.get("type") if obj.get("type") is not None else 'boundingBox',
            "classAttributesSelections": obj.get("classAttributesSelections"),
            "classInformation": ClassInformation.from_dict(obj["classInformation"]) if obj.get("classInformation") is not None else None,
            "x": obj.get("x"),
            "y": obj.get("y"),
            "width": obj.get("width"),
            "height": obj.get("height"),
            "fill": obj.get("fill"),
            "stroke": obj.get("stroke")
        })
        return _obj


