# coding: utf-8

"""
    Generated by: https://openapi-generator.tech
"""

from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBytes, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from regula.facesdk.webclient.gen.models.person_with_images import PersonWithImages
from typing import Optional, Set
from typing_extensions import Self
from pydantic import SkipValidation, Field

class FacesResponse(BaseModel):
    """
    FacesResponse
    """ # noqa: E501
    face_index: SkipValidation[Optional[float]] = Field(alias="faceIndex", default=None, description="The detected face index number.")
    landmarks: SkipValidation[Optional[List[List[float]]]] = Field(alias="landmarks", default=None, description="Absolute coordinates (x,y) of five points of each detected face: left eye, right eye, nose, left point of lips, right point of lips.")
    rotation_angle: SkipValidation[Optional[float]] = Field(alias="rotationAngle", default=None, description="Angle of rotation of the face from the vertical axis, degrees.")
    roi: SkipValidation[Optional[List[float]]] = Field(alias="roi", default=None, description="The rectangular area of a detected face that is represented by a set of four elements: the X and Y coordinates of the top-left point, and the width and height dimensions of the rectangle.")
    crop: SkipValidation[Optional[bytearray]] = Field(alias="crop", default=None, description="Base64-encoded aligned and cropped portrait.")
    persons: SkipValidation[Optional[List[PersonWithImages]]] = Field(alias="persons", default=None, description="Detected Persons.")
    __properties: ClassVar[List[str]] = ["faceIndex", "landmarks", "rotationAngle", "roi", "crop", "persons"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
        arbitrary_types_allowed=True,
        use_enum_values=True
    )


    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 FacesResponse 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 each item in persons (list)
        _items = []
        if self.persons:
            for _item_persons in self.persons:
                if _item_persons:
                    _items.append(_item_persons.to_dict())
            _dict['persons'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "faceIndex": obj.get("faceIndex"),
            "landmarks": obj.get("landmarks"),
            "rotationAngle": obj.get("rotationAngle"),
            "roi": obj.get("roi"),
            "crop": obj.get("crop"),
            "persons": [PersonWithImages.from_dict(_item) for _item in obj.get("persons", []) if PersonWithImages.from_dict(_item) is not None]
        })
        return _obj


