# coding: utf-8

"""
    Acre Platform User API

    # CORS CORS is implemented by all Acre API endpoints and only certain hostnames are allowed for each deployment of the API. If your use case requires calling the Acre User API from a browser, please contact Acre to arrange the appropriate configuration. # API Authentication The primary method of authentication for users of the Acre API is with the use of JSON Web Tokens (JWTs), which are suplemented by an application specific API Key. The API key must be provided through the `X-API-KEY` HTTP header and will be provided by your Acre Customer Success Manager. The JWT must be provided through a cookie with key of `authorization`. The JWT must be generated and signed as per the following section. # Generating JWTs JWT must either be generated by a third-party such as Azure ADB2C that has been configured for the appropriate service and/or user account, or alternatively can be generated locally and signed by an private key for which the public key has been made available to Acre via a JWKS URL. In addition to being signed by your private key, the JWT will also need to contain at a minimum:  * An issuer `iss`, which must be a valid URI previously agreed with Acre.  * A subject `sub`, which must be a unique identifier for the user and/or service account previously agreed with Acre.  * An expiry time `exp` which must not be more than four hours in the future.  * A not before time `nbf` which must be in the past, but not greater than six hours in the past.  The JWT should be signed using RS256.

    The version of the OpenAPI document: 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from acre_api.models.cdm_additional_supplementary_information import CdmAdditionalSupplementaryInformation
from acre_api.models.cdm_arrears_summary import CdmArrearsSummary
from acre_api.models.cdm_client_outstanding_debt_default_event import CdmClientOutstandingDebtDefaultEvent
from acre_api.models.cdm_company_class import CdmCompanyClass
from acre_api.models.cdm_frequency import CdmFrequency
from acre_api.models.cdm_payment_history import CdmPaymentHistory
from acre_api.models.cdm_supplementary_information import CdmSupplementaryInformation
from acre_api.models.client_outstanding_debt_account_status import ClientOutstandingDebtAccountStatus
from acre_api.models.client_outstanding_debt_borrower_type import ClientOutstandingDebtBorrowerType
from acre_api.models.client_outstanding_debt_commitment_type import ClientOutstandingDebtCommitmentType
from acre_api.models.client_outstanding_debt_repayment_status_type import ClientOutstandingDebtRepaymentStatusType
from typing import Optional, Set
from typing_extensions import Self

class CdmClientOutstandingDebt(BaseModel):
    """
    CdmClientOutstandingDebt
    """ # noqa: E501
    commitment_type: Optional[ClientOutstandingDebtCommitmentType] = ClientOutstandingDebtCommitmentType.INVALID_COMMITMENT_TYPE
    borrower_type: Optional[ClientOutstandingDebtBorrowerType] = ClientOutstandingDebtBorrowerType.INVALID_BORROWER_TYPE
    amount_outstanding: Optional[StrictStr] = Field(default=None, description="The amount outstanding on the commitment (in pence, not GBP).")
    monthly_repayment_amount: Optional[StrictStr] = Field(default=None, description="The monthly repayment amount on the commitment (in pence, not GBP).")
    name_of_creditor: Optional[StrictStr] = Field(default=None, description="The name of the creditor.")
    reference_account_no: Optional[StrictStr] = Field(default=None, description="The reference number of the account.")
    final_repayment_date: Optional[StrictStr] = Field(default=None, description="The date of the final repayment (YYYY-MM-DD).")
    repaid_before_mortgage_commences: Optional[StrictBool] = Field(default=None, description="Flag indicating whether this debt will be repaid before the mortgage commences.")
    credit_limit: Optional[StrictStr] = Field(default=None, description="The credit limit for applicable commitment types (in pence, not GBP).")
    additional_details: Optional[StrictStr] = Field(default=None, description="Any additional details provided for this commitment.")
    repaid_each_month: Optional[StrictBool] = Field(default=None, description="Flag to capture if credit card debt is paid in full each month.")
    interest_rate: Optional[StrictInt] = Field(default=None, description="Interest rate on outstanding debt, represented as 1/100000 of a percent (precision for up to 5 decimal places).  DEPRECATED: due to GBP to pence conversion.  string amount_outstanding = 3;  string monthly_repayment_amount = 4;  string credit_limit = 9;")
    to_be_consolidated: Optional[StrictBool] = Field(default=None, description="Will the debt be consolidated into mortgage debt.")
    repayment_amount: Optional[StrictStr] = Field(default=None, description="Total amount to be repaid  (in pence).")
    repayment_frequency: Optional[CdmFrequency] = CdmFrequency.INVALID
    start_date: Optional[StrictStr] = Field(default=None, description="The start date of the credit agreement (YYYY-MM-DD).")
    term_in_months: Optional[StrictInt] = Field(default=None, description="The duration of the credit agreement expressed in months.")
    payment_status_summary: Optional[ClientOutstandingDebtRepaymentStatusType] = ClientOutstandingDebtRepaymentStatusType.INVALID_STATUS
    end_date: Optional[StrictStr] = Field(default=None, description="Debt end date (YYYY-MM-DD).")
    payment_history: Optional[List[CdmPaymentHistory]] = Field(default=None, description="History of repayments.")
    arrears_summary: Optional[CdmArrearsSummary] = None
    default_event: Optional[CdmClientOutstandingDebtDefaultEvent] = None
    last_update_date: Optional[StrictStr] = Field(default=None, description="The date of the last update on the debt (YYYY-MM-DD).")
    id: Optional[StrictStr] = Field(default=None, description="A unique identifier for this entry.")
    account_status: Optional[ClientOutstandingDebtAccountStatus] = ClientOutstandingDebtAccountStatus.INVALID_ACCOUNT_STATUS
    company_class: Optional[CdmCompanyClass] = CdmCompanyClass.INVALID_COMPANY_CLASS
    supplementary_information: Optional[CdmSupplementaryInformation] = CdmSupplementaryInformation.INVALID_SUPPLEMENTARY_INFORMATION
    additional_supplementary_information: Optional[CdmAdditionalSupplementaryInformation] = CdmAdditionalSupplementaryInformation.INVALID_ADDITIONAL_SUPPLEMENTARY_INFORMATION
    __properties: ClassVar[List[str]] = ["commitment_type", "borrower_type", "amount_outstanding", "monthly_repayment_amount", "name_of_creditor", "reference_account_no", "final_repayment_date", "repaid_before_mortgage_commences", "credit_limit", "additional_details", "repaid_each_month", "interest_rate", "to_be_consolidated", "repayment_amount", "repayment_frequency", "start_date", "term_in_months", "payment_status_summary", "end_date", "payment_history", "arrears_summary", "default_event", "last_update_date", "id", "account_status", "company_class", "supplementary_information", "additional_supplementary_information"]

    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 CdmClientOutstandingDebt 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 payment_history (list)
        _items = []
        if self.payment_history:
            for _item_payment_history in self.payment_history:
                if _item_payment_history:
                    _items.append(_item_payment_history.to_dict())
            _dict['payment_history'] = _items
        # override the default output from pydantic by calling `to_dict()` of arrears_summary
        if self.arrears_summary:
            _dict['arrears_summary'] = self.arrears_summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of default_event
        if self.default_event:
            _dict['default_event'] = self.default_event.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "commitment_type": obj.get("commitment_type") if obj.get("commitment_type") is not None else ClientOutstandingDebtCommitmentType.INVALID_COMMITMENT_TYPE,
            "borrower_type": obj.get("borrower_type") if obj.get("borrower_type") is not None else ClientOutstandingDebtBorrowerType.INVALID_BORROWER_TYPE,
            "amount_outstanding": obj.get("amount_outstanding"),
            "monthly_repayment_amount": obj.get("monthly_repayment_amount"),
            "name_of_creditor": obj.get("name_of_creditor"),
            "reference_account_no": obj.get("reference_account_no"),
            "final_repayment_date": obj.get("final_repayment_date"),
            "repaid_before_mortgage_commences": obj.get("repaid_before_mortgage_commences"),
            "credit_limit": obj.get("credit_limit"),
            "additional_details": obj.get("additional_details"),
            "repaid_each_month": obj.get("repaid_each_month"),
            "interest_rate": obj.get("interest_rate"),
            "to_be_consolidated": obj.get("to_be_consolidated"),
            "repayment_amount": obj.get("repayment_amount"),
            "repayment_frequency": obj.get("repayment_frequency") if obj.get("repayment_frequency") is not None else CdmFrequency.INVALID,
            "start_date": obj.get("start_date"),
            "term_in_months": obj.get("term_in_months"),
            "payment_status_summary": obj.get("payment_status_summary") if obj.get("payment_status_summary") is not None else ClientOutstandingDebtRepaymentStatusType.INVALID_STATUS,
            "end_date": obj.get("end_date"),
            "payment_history": [CdmPaymentHistory.from_dict(_item) for _item in obj["payment_history"]] if obj.get("payment_history") is not None else None,
            "arrears_summary": CdmArrearsSummary.from_dict(obj["arrears_summary"]) if obj.get("arrears_summary") is not None else None,
            "default_event": CdmClientOutstandingDebtDefaultEvent.from_dict(obj["default_event"]) if obj.get("default_event") is not None else None,
            "last_update_date": obj.get("last_update_date"),
            "id": obj.get("id"),
            "account_status": obj.get("account_status") if obj.get("account_status") is not None else ClientOutstandingDebtAccountStatus.INVALID_ACCOUNT_STATUS,
            "company_class": obj.get("company_class") if obj.get("company_class") is not None else CdmCompanyClass.INVALID_COMPANY_CLASS,
            "supplementary_information": obj.get("supplementary_information") if obj.get("supplementary_information") is not None else CdmSupplementaryInformation.INVALID_SUPPLEMENTARY_INFORMATION,
            "additional_supplementary_information": obj.get("additional_supplementary_information") if obj.get("additional_supplementary_information") is not None else CdmAdditionalSupplementaryInformation.INVALID_ADDITIONAL_SUPPLEMENTARY_INFORMATION
        })
        return _obj


