# 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 json
import pprint
import re  # noqa: F401
from datetime import datetime
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import (
    BaseModel,
    ConfigDict,
    Field,
    StrictBool,
    StrictStr,
    field_validator,
)
from typing_extensions import Self

from eazyrent.core.v2.models.tag_in import TagIn


class PartialUpdateRentalFile(BaseModel):
    """
    Schema for PATCH /v2/rental-files/:id
    """  # noqa: E501

    product_id: Optional[StrictStr] = None
    meta: Optional[Any] = None
    allow_user_engagement: Optional[StrictBool] = Field(
        default=True,
        description="If enabled, applicants will be able to access their data, and the system will allow email sending",
    )
    archived_at: Optional[datetime] = None
    tags: Optional[List[TagIn]] = None
    managers: Optional[List[StrictStr]] = None
    applicants_situation: Optional[StrictStr] = None
    decision: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "product_id",
        "meta",
        "allow_user_engagement",
        "archived_at",
        "tags",
        "managers",
        "applicants_situation",
        "decision",
    ]

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

        if value not in set(["SINGLE", "COUPLE", "ROOMATES", "SOLID_ROOMATES"]):
            raise ValueError(
                "must be one of enum values ('SINGLE', 'COUPLE', 'ROOMATES', 'SOLID_ROOMATES')"
            )
        return value

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

        if value not in set(["ACCEPTED", "REJECTED", "PENDING", "READY"]):
            raise ValueError(
                "must be one of enum values ('ACCEPTED', 'REJECTED', 'PENDING', 'READY')"
            )
        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 PartialUpdateRentalFile 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 tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict["tags"] = _items
        # set to None if product_id (nullable) is None
        # and model_fields_set contains the field
        if self.product_id is None and "product_id" in self.model_fields_set:
            _dict["product_id"] = 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 archived_at (nullable) is None
        # and model_fields_set contains the field
        if self.archived_at is None and "archived_at" in self.model_fields_set:
            _dict["archived_at"] = 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 managers (nullable) is None
        # and model_fields_set contains the field
        if self.managers is None and "managers" in self.model_fields_set:
            _dict["managers"] = 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 decision (nullable) is None
        # and model_fields_set contains the field
        if self.decision is None and "decision" in self.model_fields_set:
            _dict["decision"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "product_id": obj.get("product_id"),
                "meta": obj.get("meta"),
                "allow_user_engagement": obj.get("allow_user_engagement")
                if obj.get("allow_user_engagement") is not None
                else True,
                "archived_at": obj.get("archived_at"),
                "tags": [TagIn.from_dict(_item) for _item in obj["tags"]]
                if obj.get("tags") is not None
                else None,
                "managers": obj.get("managers"),
                "applicants_situation": obj.get("applicants_situation"),
                "decision": obj.get("decision"),
            }
        )
        return _obj
