# coding: utf-8

"""
    Eazyrent core API

    EazyRent Core API ====================  Description -------------  The EazyRent API is a powerful tool, designed to automate and streamline the tenant application process for professionals in the real estate and insurance sectors.  Our API leverages advanced technologies like Optical Character Recognition (OCR) and Machine Learning to collect, analyze, and verify tenant application documents.  The API helps clients detect fraudulent submissions and assess the reliability of potential tenants, ensuring a secure and efficient tenant selection process.  Target Audience ----------------   * **Real Estate Agencies and Social Housing Providers:** Professionals who need a reliable solution to evaluate tenant applications quickly and accurately.   * **Rent Guarantee Insurers:** Companies seeking to verify the credibility of tenant applications and assess eligibility for rent payment guarantees.   Purpose --------  The purpose of the EazyRent API is to enable seamless interaction with our tenant application system. It allows clients to integrate our automated document collection, analysis, and verification capabilities directly into their own workflows. By using our API, businesses can streamline operations, reduce fraud risk, and make well-informed decisions in the tenant selection process.   How to use this API ---------------------  To start using the EazyRent API, please refer to our comprehensive online documentation, which includes detailed information on API endpoints, authentication, and integration examples. You can access the documentation [here](https://docs.eazyrent.fr). This resource will guide you through the steps needed to integrate our API into your existing systems and maximize its capabilities.  

    The version of the OpenAPI document: 2
    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 datetime import datetime
from pydantic import (
    BaseModel,
    ConfigDict,
    StrictBool,
    StrictFloat,
    StrictInt,
    StrictStr,
    field_validator,
)
from typing import Any, ClassVar, Dict, List, Optional, Union
from eazyrent.core.v2.models.moral_guarantor import MoralGuarantor
from typing import Optional, Set
from typing_extensions import Self


class ListApplicant(BaseModel):
    """
    ListApplicant
    """  # noqa: E501

    first_name: Optional[StrictStr] = None
    last_name: Optional[StrictStr] = None
    email: Optional[StrictStr] = None
    phone: Optional[StrictStr] = None
    id: Optional[StrictStr] = None
    status: Optional[StrictStr] = "NEW"
    form_submitted: Optional[datetime] = None
    score: Optional[Union[StrictFloat, StrictInt]] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    is_guarantor: Optional[StrictBool] = False
    physical_guarantors: Optional[List[ListApplicant]] = None
    moral_guarantor: Optional[MoralGuarantor] = None
    meta: Optional[Any] = None
    profile: Optional[StrictStr] = None
    completion_rate: Optional[Union[StrictFloat, StrictInt]] = None
    is_pre_application: Optional[StrictBool] = False
    pre_application_validated_at: Optional[datetime] = None
    __properties: ClassVar[List[str]] = [
        "first_name",
        "last_name",
        "email",
        "phone",
        "id",
        "status",
        "form_submitted",
        "score",
        "created_at",
        "updated_at",
        "is_guarantor",
        "physical_guarantors",
        "moral_guarantor",
        "meta",
        "profile",
        "completion_rate",
        "is_pre_application",
        "pre_application_validated_at",
    ]

    @field_validator("status")
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(
            [
                "NEW",
                "OPEN",
                "COLLECT_STARTED",
                "COLLECT_COMPLETE",
                "COLLECTED",
                "ANALYZED",
                "CLOSED",
            ]
        ):
            raise ValueError(
                "must be one of enum values ('NEW', 'OPEN', 'COLLECT_STARTED', 'COLLECT_COMPLETE', 'COLLECTED', 'ANALYZED', 'CLOSED')"
            )
        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 ListApplicant 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 physical_guarantors (list)
        _items = []
        if self.physical_guarantors:
            for _item_physical_guarantors in self.physical_guarantors:
                if _item_physical_guarantors:
                    _items.append(_item_physical_guarantors.to_dict())
            _dict["physical_guarantors"] = _items
        # override the default output from pydantic by calling `to_dict()` of moral_guarantor
        if self.moral_guarantor:
            _dict["moral_guarantor"] = self.moral_guarantor.to_dict()
        # set to None if first_name (nullable) is None
        # and model_fields_set contains the field
        if self.first_name is None and "first_name" in self.model_fields_set:
            _dict["first_name"] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "first_name": obj.get("first_name"),
                "last_name": obj.get("last_name"),
                "email": obj.get("email"),
                "phone": obj.get("phone"),
                "id": obj.get("id"),
                "status": obj.get("status") if obj.get("status") is not None else "NEW",
                "form_submitted": obj.get("form_submitted"),
                "score": obj.get("score"),
                "created_at": obj.get("created_at"),
                "updated_at": obj.get("updated_at"),
                "is_guarantor": obj.get("is_guarantor")
                if obj.get("is_guarantor") is not None
                else False,
                "physical_guarantors": [
                    ListApplicant.from_dict(_item)
                    for _item in obj["physical_guarantors"]
                ]
                if obj.get("physical_guarantors") is not None
                else None,
                "moral_guarantor": MoralGuarantor.from_dict(obj["moral_guarantor"])
                if obj.get("moral_guarantor") is not None
                else None,
                "meta": obj.get("meta"),
                "profile": obj.get("profile"),
                "completion_rate": obj.get("completion_rate"),
                "is_pre_application": obj.get("is_pre_application")
                if obj.get("is_pre_application") is not None
                else False,
                "pre_application_validated_at": obj.get("pre_application_validated_at"),
            }
        )
        return _obj


# TODO: Rewrite to not use raise_errors
ListApplicant.model_rebuild(raise_errors=False)
