# 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: 0.41.0
    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 typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, conlist
from synctera_client_ng.models.transaction_line1 import TransactionLine1

class PostedTransactionData(BaseModel):
    """NOTE: This class is auto generated by OpenAPI Generator.
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """
    external_data: Optional[Dict[str, Any]] = Field(None, description="an unstructured json blob representing additional transaction information supplied by the integrator.")
    force_post: StrictBool = Field(..., description="Whether or not the hold was forced (spending controls ignored)")
    hold_id: Optional[StrictStr] = Field(None, description="The uuid of the hold (pending transaction) that this transaction originated from, if any.")
    lines: conlist(TransactionLine1) = Field(..., description="The set of accounting entries associated with this transaction. For example, a debit to a customer account will have a corresponding credit in a general ledger account.")
    memo: StrictStr = Field(..., description="A short note to the recipient")
    metadata: Optional[Dict[str, Any]] = ...
    original_trx: Optional[StrictStr] = Field(None, description="The \"original\" transaction that this transaction is related to. This is only populated in the case of reversed transactions.")
    parent_trx: Optional[StrictStr] = Field(None, description="The \"parent\" transaction that this transaction is related to. This is only populated in the case of scheduled transactions.")
    risk_info: Optional[Dict[str, Any]] = Field(None, description="Information received by the transaction risk/fraud service related to this transaction")
    user_data: Optional[Dict[str, Any]] = Field(None, description="An unstructured JSON blob representing additional transaction information specific to each payment rail.")
    __properties = ["external_data", "force_post", "hold_id", "lines", "memo", "metadata", "original_trx", "parent_trx", "risk_info", "user_data"]

    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) -> PostedTransactionData:
        """Create an instance of PostedTransactionData 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 each item in lines (list)
        _items = []
        if self.lines:
            for _item in self.lines:
                if _item:
                    _items.append(_item.to_dict())
            _dict['lines'] = _items
        # set to None if external_data (nullable) is None
        if self.external_data is None:
            _dict['external_data'] = None

        # set to None if metadata (nullable) is None
        if self.metadata is None:
            _dict['metadata'] = None

        # set to None if risk_info (nullable) is None
        if self.risk_info is None:
            _dict['risk_info'] = None

        # set to None if user_data (nullable) is None
        if self.user_data is None:
            _dict['user_data'] = None

        return _dict

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

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

        _obj = PostedTransactionData.parse_obj({
            "external_data": obj.get("external_data"),
            "force_post": obj.get("force_post"),
            "hold_id": obj.get("hold_id"),
            "lines": [TransactionLine1.from_dict(_item) for _item in obj.get("lines")] if obj.get("lines") is not None else None,
            "memo": obj.get("memo"),
            "metadata": obj.get("metadata"),
            "original_trx": obj.get("original_trx"),
            "parent_trx": obj.get("parent_trx"),
            "risk_info": obj.get("risk_info"),
            "user_data": obj.get("user_data")
        })
        return _obj

