{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Account",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "_id": {
            "type": "integer",
            "description": "A unique ID for Account"
        },
        "accountType": {
            "type": "string",
            "enum": [
                "BANKING",
                "CREDIT_CARD",
                "CASH",
                "ASSET",
                "LIABILITY",
                "INVESTMENT",
                "LOAN",
                "UNKNOWN"
            ],
            "description": "An account type."
        },
        "closed": {
            "type": "boolean",
            "description": "True if account is closed."
        },
        "creditCardAmountLimit": {
            "type": "number",
            "description": "For credit card, card amount limit."
        },
        "currency": {
            "$ref": "#/definitions/MnyCurrency",
            "description": "Currency for this account"
        },
        "currentBalance": {
            "type": "number",
            "description": "Current balance for this account."
        },
        "filteredTransactions": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/Transaction"
            },
            "description": "A list of transactions associated to this account but does NOT contributed to its balance."
        },
        "investmentSubType": {
            "type": "string",
            "enum": [
                "_403b",
                "_401k",
                "IRA",
                "KEOGH",
                "RETIREMENT",
                "NOT_APPLICABLE",
                "UNKNOWN"
            ],
            "description": "Only meaningful for investment account."
        },
        "name": {
            "type": "string",
            "description": "Name of the account. This value is mutable. User can change it."
        },
        "relatedToAccount": {
            "$ref": "#/definitions/Account",
            "description": "Ususally, only non-null for Investment account which has associated Cash account and vice-versa."
        },
        "retirement": {
            "type": "boolean",
            "description": "Only true if this account is a retirement account."
        },
        "securityHoldings": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/SecurityHolding"
            },
            "description": "Only for Investment account, list of security holding."
        },
        "startingBalance": {
            "type": "number",
            "description": "Account starting balance."
        },
        "transactions": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/Transaction"
            },
            "description": "List of transactions."
        }
    },
    "definitions": {
        "MnyCurrency": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for MnyCurrency"
                },
                "code": {
                    "type": "string"
                }
            }
        },
        "Transaction": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Transaction"
                },
                "account": {
                    "$ref": "#/definitions/AccountLink"
                },
                "amount": {
                    "type": "number"
                },
                "category": {
                    "$ref": "#/definitions/CategoryLink"
                },
                "classification1": {
                    "$ref": "#/definitions/Classification1Link"
                },
                "cleared": {
                    "type": "boolean"
                },
                "clearedState": {
                    "type": "integer"
                },
                "date": {
                    "type": "string",
                    "format": "date-time"
                },
                "fiTransactionId": {
                    "type": "string"
                },
                "frequency": {
                    "$ref": "#/definitions/Frequency"
                },
                "investment": {
                    "type": "boolean"
                },
                "investmentInfo": {
                    "$ref": "#/definitions/InvestmentInfo"
                },
                "memo": {
                    "type": "string"
                },
                "number": {
                    "type": "string"
                },
                "payee": {
                    "$ref": "#/definitions/PayeeLink"
                },
                "reconciled": {
                    "type": "boolean"
                },
                "recurring": {
                    "type": "boolean"
                },
                "splits": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/TransactionSplit"
                    }
                },
                "state": {
                    "type": "string",
                    "enum": [
                        "UNRECONCILED",
                        "RECONCILED",
                        "CLEARED",
                        "VOID"
                    ]
                },
                "statusFlag": {
                    "type": "integer"
                },
                "transactionInfo": {
                    "$ref": "#/definitions/TransactionInfo"
                },
                "transfer": {
                    "type": "boolean"
                },
                "unaccepted": {
                    "type": "boolean"
                },
                "void": {
                    "type": "boolean"
                },
                "xferInfo": {
                    "$ref": "#/definitions/XferInfo"
                }
            },
            "required": [
                "cleared",
                "investment",
                "reconciled",
                "recurring",
                "transfer",
                "unaccepted",
                "void"
            ]
        },
        "AccountLink": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Account"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "CategoryLink": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Category"
                },
                "fullName": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "parentId": {
                    "type": "integer"
                },
                "parentName": {
                    "type": "string"
                }
            }
        },
        "Classification1Link": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Classification1"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "Frequency": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "label": {
                    "type": "string"
                },
                "recurring": {
                    "type": "boolean"
                },
                "type": {
                    "type": "integer"
                }
            },
            "required": [
                "recurring"
            ]
        },
        "InvestmentInfo": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "activity": {
                    "$ref": "#/definitions/InvestmentActivity"
                },
                "security": {
                    "$ref": "#/definitions/Security"
                },
                "transaction": {
                    "$ref": "#/definitions/InvestmentTransaction"
                }
            }
        },
        "InvestmentActivity": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "label": {
                    "type": "string"
                },
                "type": {
                    "type": "integer"
                }
            }
        },
        "Security": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Security"
                },
                "name": {
                    "type": "string"
                },
                "symbol": {
                    "type": "string"
                }
            }
        },
        "InvestmentTransaction": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for InvestmentTransaction"
                },
                "price": {
                    "type": "number"
                },
                "quantity": {
                    "type": "number"
                }
            }
        },
        "PayeeLink": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Payee"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "TransactionSplit": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "parentId": {
                    "type": "integer"
                },
                "rowId": {
                    "type": "integer"
                },
                "transaction": {
                    "$ref": "#/definitions/Transaction"
                }
            }
        },
        "TransactionInfo": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "flag": {
                    "type": "integer"
                },
                "investment": {
                    "type": "boolean"
                },
                "splitChild": {
                    "type": "boolean"
                },
                "splitParent": {
                    "type": "boolean"
                },
                "transfer": {
                    "type": "boolean"
                },
                "transferTo": {
                    "type": "boolean"
                },
                "void": {
                    "type": "boolean"
                }
            },
            "required": [
                "investment",
                "splitChild",
                "splitParent",
                "transfer",
                "transferTo",
                "void"
            ]
        },
        "XferInfo": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "xferAccountId": {
                    "type": "integer"
                },
                "xferTransactionId": {
                    "type": "integer"
                }
            }
        },
        "Account": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "_id": {
                    "type": "integer",
                    "description": "A unique ID for Account"
                },
                "accountType": {
                    "type": "string",
                    "enum": [
                        "BANKING",
                        "CREDIT_CARD",
                        "CASH",
                        "ASSET",
                        "LIABILITY",
                        "INVESTMENT",
                        "LOAN",
                        "UNKNOWN"
                    ],
                    "description": "An account type."
                },
                "closed": {
                    "type": "boolean",
                    "description": "True if account is closed."
                },
                "creditCardAmountLimit": {
                    "type": "number",
                    "description": "For credit card, card amount limit."
                },
                "currency": {
                    "$ref": "#/definitions/MnyCurrency",
                    "description": "Currency for this account"
                },
                "currentBalance": {
                    "type": "number",
                    "description": "Current balance for this account."
                },
                "filteredTransactions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Transaction"
                    },
                    "description": "A list of transactions associated to this account but does NOT contributed to its balance."
                },
                "investmentSubType": {
                    "type": "string",
                    "enum": [
                        "_403b",
                        "_401k",
                        "IRA",
                        "KEOGH",
                        "RETIREMENT",
                        "NOT_APPLICABLE",
                        "UNKNOWN"
                    ],
                    "description": "Only meaningful for investment account."
                },
                "name": {
                    "type": "string",
                    "description": "Name of the account. This value is mutable. User can change it."
                },
                "relatedToAccount": {
                    "$ref": "#/definitions/Account",
                    "description": "Ususally, only non-null for Investment account which has associated Cash account and vice-versa."
                },
                "retirement": {
                    "type": "boolean",
                    "description": "Only true if this account is a retirement account."
                },
                "securityHoldings": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/SecurityHolding"
                    },
                    "description": "Only for Investment account, list of security holding."
                },
                "startingBalance": {
                    "type": "number",
                    "description": "Account starting balance."
                },
                "transactions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Transaction"
                    },
                    "description": "List of transactions."
                }
            }
        },
        "SecurityHolding": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "marketValue": {
                    "type": "number"
                },
                "price": {
                    "type": "number"
                },
                "quantity": {
                    "type": "number"
                },
                "security": {
                    "$ref": "#/definitions/Security"
                }
            }
        }
    }
}