# coding: utf-8

"""
    Synctera API

    <h2>Let's build something great.</h2><p>Welcome to the official reference documentation for Synctera APIs. Our APIs are the best way to automate your company's banking needs and are designed to be easy to understand and implement.</p><p>We're continuously growing this library and what you see here is just the start, but if you need something specific or have a question, <a class='text-blue-600' href='https://synctera.com/contact' target='_blank' rel='noreferrer'>contact us</a>.</p>  # noqa: E501

    The version of the OpenAPI document: 1.41.3
    Contact: dev@swadesh.co
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
from inspect import getfullargspec
import pprint
import re  # noqa: F401
import json

from datetime import date, datetime
from typing import Any, Dict, Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, validator
from synctera_client_v1.models.base_transaction_decline import BaseTransactionDecline
from synctera_client_v1.models.enhanced_transaction_data1 import EnhancedTransactionData1
from synctera_client_v1.models.fraud_risk_data import FraudRiskData
from synctera_client_v1.models.transaction_statuses import TransactionStatuses
from synctera_client_v1.models.transaction_types import TransactionTypes

class BaseTransaction(BaseModel):
    """
    BaseTransaction
    """
    account_id: Optional[StrictStr] = Field(None, description="The account uuid associated with the transaction. `account_id` and `internal_account_id` are mutually exclusive")
    amount: StrictInt = Field(..., description="The total amount of the transaction including both pending and already posted amounts. The value is represented as the smallest denomination of the applicable currency.")
    creation_time: datetime = Field(..., description="The exact time the transaction was recorded in the ledger")
    currency: StrictStr = Field(..., description="ISO 4217 alphabetic currency code of the transfer amount")
    customer_id: Optional[StrictStr] = Field(None, description="The uuid of the customer that initiated the transaction (if any) ")
    dc_sign: StrictStr = Field(..., description="The `dc_sign` represents the direction money was moved. A value of `DEBIT` is money moving out of an account, a value of `CREDIT` is money moving into an account")
    decline: Optional[BaseTransactionDecline] = None
    description: Optional[StrictStr] = Field(None, description="A human-friendly description of the transaction, provided by the integrator")
    effective_date: date = Field(..., description="The effective date of the transaction. This usually aligns with network settlement date, which differs between transaction types. The effective date is also used to determine effective daily balances for the purposes of interest calculation.")
    enhanced_transaction: Optional[EnhancedTransactionData1] = None
    force_post: StrictBool = Field(..., description="Determines whether or not a transaction or auth was \"forced\" or not. A forced transaction skips any account balance checks")
    fraud_risk: Optional[FraudRiskData] = None
    group_id: StrictStr = Field(..., description="The group id of the transaction. Every transaction in the ledger is one entry in a double-entry system and the primary and offset transactions share the same `group_id`")
    hold_expiration_time: Optional[datetime] = Field(None, description="The date and time any pending amount is expected to be released back to the account.")
    id: StrictStr = Field(..., description="The unique identifier of the transaction")
    internal_account_id: Optional[StrictStr] = Field(None, description="The internal account uuid associated with the transaction. `account_id` and `internal_account_id` are mutually exclusive")
    last_updated_time: datetime = Field(..., description="The date and time the transaction was last modified")
    metadata: Optional[Dict[str, Any]] = Field(None, description="an unstructured json blob representing additional transaction information supplied by the integrator.")
    partial_hold: StrictBool = Field(..., description="Determines whether or not the funds on hold were the result of a partial auth or not. If `true` the `pending_amount` of the transaction will be less than the requested amount. This is primarily used for certain types of card transactions.")
    pending_amount: StrictInt = Field(..., description="The amount amount of the transaction currently authorized or on hold")
    posted_amount: StrictInt = Field(..., description="The amount of the transaction that has been fully posted to the account")
    posted_date: Optional[date] = Field(None, description="The date the transaction was posted (based on the bank calendar and end-of-day). For transaction with multiple postings, this is the date of the earliest posting. This will be omitted for transactions with a `posted_amount` of `0`.")
    reference_id: Optional[StrictStr] = Field(None, description="An external ID provided by the payment network to represent this transaction. This is not guaranteed to be globally unique. This will always be omitted for internal transfers.")
    status: TransactionStatuses = Field(...)
    system_description: Optional[StrictStr] = Field(None, description="A human-friendly description of the transaction, provided by the Synctera platform")
    transaction_time: datetime = Field(..., description="The time the transaction occurred. In most cases this will be roughly identical to creation_time, but it can differ in some situations if the payment doesn't appear in the ledger in real-time.")
    type: TransactionTypes = Field(...)
    __properties = ["account_id", "amount", "creation_time", "currency", "customer_id", "dc_sign", "decline", "description", "effective_date", "enhanced_transaction", "force_post", "fraud_risk", "group_id", "hold_expiration_time", "id", "internal_account_id", "last_updated_time", "metadata", "partial_hold", "pending_amount", "posted_amount", "posted_date", "reference_id", "status", "system_description", "transaction_time", "type"]

    @validator('dc_sign')
    def dc_sign_validate_enum(cls, v):
        if v not in ('CREDIT', 'DEBIT'):
            raise ValueError("must be one of enum values ('CREDIT', 'DEBIT')")
        return v

    class Config:
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> BaseTransaction:
        """Create an instance of BaseTransaction from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of decline
        if self.decline:
            _dict['decline'] = self.decline.to_dict()
        # override the default output from pydantic by calling `to_dict()` of enhanced_transaction
        if self.enhanced_transaction:
            _dict['enhanced_transaction'] = self.enhanced_transaction.to_dict()
        # override the default output from pydantic by calling `to_dict()` of fraud_risk
        if self.fraud_risk:
            _dict['fraud_risk'] = self.fraud_risk.to_dict()
        # set to None if metadata (nullable) is None
        # and __fields_set__ contains the field
        if self.metadata is None and "metadata" in self.__fields_set__:
            _dict['metadata'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> BaseTransaction:
        """Create an instance of BaseTransaction from a dict"""
        if obj is None:
            return None

        if type(obj) is not dict:
            return BaseTransaction.parse_obj(obj)

        _obj = BaseTransaction.parse_obj({
            "account_id": obj.get("account_id"),
            "amount": obj.get("amount"),
            "creation_time": obj.get("creation_time"),
            "currency": obj.get("currency"),
            "customer_id": obj.get("customer_id"),
            "dc_sign": obj.get("dc_sign"),
            "decline": BaseTransactionDecline.from_dict(obj.get("decline")) if obj.get("decline") is not None else None,
            "description": obj.get("description"),
            "effective_date": obj.get("effective_date"),
            "enhanced_transaction": EnhancedTransactionData1.from_dict(obj.get("enhanced_transaction")) if obj.get("enhanced_transaction") is not None else None,
            "force_post": obj.get("force_post"),
            "fraud_risk": FraudRiskData.from_dict(obj.get("fraud_risk")) if obj.get("fraud_risk") is not None else None,
            "group_id": obj.get("group_id"),
            "hold_expiration_time": obj.get("hold_expiration_time"),
            "id": obj.get("id"),
            "internal_account_id": obj.get("internal_account_id"),
            "last_updated_time": obj.get("last_updated_time"),
            "metadata": obj.get("metadata"),
            "partial_hold": obj.get("partial_hold"),
            "pending_amount": obj.get("pending_amount"),
            "posted_amount": obj.get("posted_amount"),
            "posted_date": obj.get("posted_date"),
            "reference_id": obj.get("reference_id"),
            "status": obj.get("status"),
            "system_description": obj.get("system_description"),
            "transaction_time": obj.get("transaction_time"),
            "type": obj.get("type")
        })
        return _obj

