# 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: 1
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set, Union

from pydantic import BaseModel, ConfigDict, StrictFloat, StrictInt, StrictStr
from typing_extensions import Self

from eazyrent.core.v1.models.applicant_list import ApplicantList
from eazyrent.core.v1.models.applicants_situation_enum import ApplicantsSituationEnum
from eazyrent.core.v1.models.property_rent_list import PropertyRentList
from eazyrent.core.v1.models.status_d7b_enum import StatusD7bEnum


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

    id: StrictStr
    status: Optional[StatusD7bEnum] = None
    property_rent: Optional[PropertyRentList] = None
    applicants: List[ApplicantList]
    created_at: datetime
    last_update: datetime
    manager: Optional[StrictStr] = None
    manager_name: Optional[StrictStr] = None
    applicants_situation: Optional[ApplicantsSituationEnum] = None
    tags: Optional[List[StrictStr]] = None
    reference: Optional[StrictStr] = None
    form_completion: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = [
        "id",
        "status",
        "property_rent",
        "applicants",
        "created_at",
        "last_update",
        "manager",
        "manager_name",
        "applicants_situation",
        "tags",
        "reference",
        "form_completion",
    ]

    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 RentalFileFull 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 property_rent
        if self.property_rent:
            _dict["property_rent"] = self.property_rent.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in applicants (list)
        _items = []
        if self.applicants:
            for _item_applicants in self.applicants:
                if _item_applicants:
                    _items.append(_item_applicants.to_dict())
            _dict["applicants"] = _items
        # set to None if status (nullable) is None
        # and model_fields_set contains the field
        if self.status is None and "status" in self.model_fields_set:
            _dict["status"] = None

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RentalFileFull 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"),
                "status": obj.get("status"),
                "property_rent": PropertyRentList.from_dict(obj["property_rent"])
                if obj.get("property_rent") is not None
                else None,
                "applicants": [
                    ApplicantList.from_dict(_item) for _item in obj["applicants"]
                ]
                if obj.get("applicants") is not None
                else None,
                "created_at": obj.get("created_at"),
                "last_update": obj.get("last_update"),
                "manager": obj.get("manager"),
                "manager_name": obj.get("manager_name"),
                "applicants_situation": obj.get("applicants_situation"),
                "tags": obj.get("tags"),
                "reference": obj.get("reference"),
                "form_completion": obj.get("form_completion"),
            }
        )
        return _obj
