# 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_mortgage_product_fee import CdmMortgageProductFee
from acre_api.models.mortgage_calculated_values_calculated_club_proc_fee import MortgageCalculatedValuesCalculatedClubProcFee
from typing import Optional, Set
from typing_extensions import Self

class CdmMortgageCalculatedValues(BaseModel):
    """
    MortgageCalculatedValues holds values calculated for the mortgage.
    """ # noqa: E501
    cost_over_initial_term_inc_fees_cashback: Optional[StrictStr] = Field(default=None, description="The total cost of the mortgage over the initial rate period including any fees, and with any cashback deducted.")
    cost_over_full_term_inc_fees_cashback: Optional[StrictStr] = Field(default=None, description="The total cost of the mortgage over the full term of the mortgage including any fees, and with any cashback deducted.")
    fees_at_origination: Optional[StrictStr] = Field(default=None, description="The total fees payable prior to or on origination; i.e. excluding deed release / mortgage discharge.")
    cost_over_initial_term_inc_fees: Optional[StrictStr] = Field(default=None, description="The cost of the mortgage over the initial period, including fees, but not accounting for any cashback.")
    cost_over_full_term_inc_fees: Optional[StrictStr] = Field(default=None, description="The cost of the mortgage over the full term, including fees, but not accounting for any cashback.")
    cost_over_initial_term_exc_fees: Optional[StrictStr] = Field(default=None, description="The total cost of the mortgage over the initial rate period, exclusive of any fees. (i.e. capital repayment + interest on capital).")
    cost_over_full_term_exc_fees: Optional[StrictStr] = Field(default=None, description="The total cost of the mortgage over the full term, exclusive of any fees. (i.e. capital repayment + interest on capital).")
    total_mortgage_fees: Optional[StrictStr] = Field(default=None, description="The total sum of all fees associated with the mortgage.")
    interest_cost_of_added_fees_full_term: Optional[StrictStr] = Field(default=None, description="The interest cost of adding the fees to the loan over the full term of the mortgage.")
    loan_total_fees_added_to_loan: Optional[StrictStr] = Field(default=None, description="The total amount of all fees added to the loan.")
    loan_total_premiums_or_insurance_added_to_loan: Optional[StrictStr] = Field(default=None, description="The total amount of all premiums or insurance fees added to the loan.")
    monthly_payment: Optional[StrictStr] = Field(default=None, description="The monthly payment amount in the initial period, same as monthly_payments[0].")
    revert_monthly_payment: Optional[StrictStr] = Field(default=None, description="The monthly payment amount in the reversionary period, same as monthly_payments[1].")
    monthly_payments: Optional[List[StrictStr]] = Field(default=None, description="Monthly payments for each of the tiers of the mortgage.")
    calculated_net_proc_fee: Optional[StrictStr] = Field(default=None, description="Calculated Net Procuration Fee for this product that will be paid to the Brokerage Firm.")
    calculated_gross_proc_fee: Optional[StrictStr] = Field(default=None, description="Calculated Net Procuration Fee (i.e. total for SBG + Brokerage Firm).")
    mortgage_origination_inc_added_fees: Optional[StrictStr] = Field(default=None, description="Calculated Net Procuration Fee (i.e. total for SBG + Brokerage Firm).")
    aprc: Optional[StrictInt] = Field(default=None, description="Calculated APRC for the mortgage (5 d.p. percentage).")
    rates_20yr_max: Optional[List[StrictInt]] = Field(default=None, description="20 year max of every tier's rate. (5 d.p. percentage).  These values are used to calculate the 20 year max APRC and monthly payments.")
    monthly_payments_20yr_max: Optional[List[StrictStr]] = Field(default=None, description="20 year max monthly payments for each of the tiers of the mortgage.")
    aprc_20yr_max: Optional[StrictInt] = Field(default=None, description="Calculated 20 year max APRC for the mortgage (5 d.p. percentage).")
    calculated_club_proc_fees: Optional[List[MortgageCalculatedValuesCalculatedClubProcFee]] = Field(default=None, description="Calculated proc fee for the mortgage clubs.")
    fees: Optional[List[CdmMortgageProductFee]] = Field(default=None, description="Mortgage Product fees used in the calculations.")
    remaining_term_months: Optional[StrictStr] = Field(default=None, description="The remaining term (in months) of the mortgage (i.e. term - the difference between the current date and the mortgage_start_date).")
    can_generate_esis: Optional[StrictBool] = Field(default=None, description="If all required fields for esis generation are populated or not.")
    __properties: ClassVar[List[str]] = ["cost_over_initial_term_inc_fees_cashback", "cost_over_full_term_inc_fees_cashback", "fees_at_origination", "cost_over_initial_term_inc_fees", "cost_over_full_term_inc_fees", "cost_over_initial_term_exc_fees", "cost_over_full_term_exc_fees", "total_mortgage_fees", "interest_cost_of_added_fees_full_term", "loan_total_fees_added_to_loan", "loan_total_premiums_or_insurance_added_to_loan", "monthly_payment", "revert_monthly_payment", "monthly_payments", "calculated_net_proc_fee", "calculated_gross_proc_fee", "mortgage_origination_inc_added_fees", "aprc", "rates_20yr_max", "monthly_payments_20yr_max", "aprc_20yr_max", "calculated_club_proc_fees", "fees", "remaining_term_months", "can_generate_esis"]

    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 CdmMortgageCalculatedValues 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 calculated_club_proc_fees (list)
        _items = []
        if self.calculated_club_proc_fees:
            for _item_calculated_club_proc_fees in self.calculated_club_proc_fees:
                if _item_calculated_club_proc_fees:
                    _items.append(_item_calculated_club_proc_fees.to_dict())
            _dict['calculated_club_proc_fees'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in fees (list)
        _items = []
        if self.fees:
            for _item_fees in self.fees:
                if _item_fees:
                    _items.append(_item_fees.to_dict())
            _dict['fees'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "cost_over_initial_term_inc_fees_cashback": obj.get("cost_over_initial_term_inc_fees_cashback"),
            "cost_over_full_term_inc_fees_cashback": obj.get("cost_over_full_term_inc_fees_cashback"),
            "fees_at_origination": obj.get("fees_at_origination"),
            "cost_over_initial_term_inc_fees": obj.get("cost_over_initial_term_inc_fees"),
            "cost_over_full_term_inc_fees": obj.get("cost_over_full_term_inc_fees"),
            "cost_over_initial_term_exc_fees": obj.get("cost_over_initial_term_exc_fees"),
            "cost_over_full_term_exc_fees": obj.get("cost_over_full_term_exc_fees"),
            "total_mortgage_fees": obj.get("total_mortgage_fees"),
            "interest_cost_of_added_fees_full_term": obj.get("interest_cost_of_added_fees_full_term"),
            "loan_total_fees_added_to_loan": obj.get("loan_total_fees_added_to_loan"),
            "loan_total_premiums_or_insurance_added_to_loan": obj.get("loan_total_premiums_or_insurance_added_to_loan"),
            "monthly_payment": obj.get("monthly_payment"),
            "revert_monthly_payment": obj.get("revert_monthly_payment"),
            "monthly_payments": obj.get("monthly_payments"),
            "calculated_net_proc_fee": obj.get("calculated_net_proc_fee"),
            "calculated_gross_proc_fee": obj.get("calculated_gross_proc_fee"),
            "mortgage_origination_inc_added_fees": obj.get("mortgage_origination_inc_added_fees"),
            "aprc": obj.get("aprc"),
            "rates_20yr_max": obj.get("rates_20yr_max"),
            "monthly_payments_20yr_max": obj.get("monthly_payments_20yr_max"),
            "aprc_20yr_max": obj.get("aprc_20yr_max"),
            "calculated_club_proc_fees": [MortgageCalculatedValuesCalculatedClubProcFee.from_dict(_item) for _item in obj["calculated_club_proc_fees"]] if obj.get("calculated_club_proc_fees") is not None else None,
            "fees": [CdmMortgageProductFee.from_dict(_item) for _item in obj["fees"]] if obj.get("fees") is not None else None,
            "remaining_term_months": obj.get("remaining_term_months"),
            "can_generate_esis": obj.get("can_generate_esis")
        })
        return _obj


