# Account Rules

The account rules determine what types of balances will be created automatically when an account is created or a currency associated with it, and determine whether an account can be created by the user or whether it is unique in the system for its desired description.

{% hint style="info" %}
<mark style="color:blue;">Notice: the type of an account (asset, liability, equity, revenue or expense) is determined in the Chart of Accounts for every account description and balance type</mark>
{% endhint %}

## Uniqueness <a href="#uniqueness" id="uniqueness"></a>

Some accounts in the system, for a given classification, will only have one account created for the operation, which will then be mapped in a fixed manner in the transactional rules and not used as transaction input parameters.

## Types of Balances <a href="#types-of-balances" id="types-of-balances"></a>

The system allows you to configure which types of balances will be automatically created for each currency in an account. Balance types are just classifications of balances that have their standard structural functioning, each having its own movement history in its currency.

## Creation or Update of Account Rules <a href="#creation-or-update-of-account-rules" id="creation-or-update-of-account-rules"></a>

The PUT /account\_rules method is used to register account creation rules individually or in batch. The same method is used to replace the rules individual or in batch.

The method will receive a rule mapping list with the following fields in each record:

| Field                | Description                                                                                                        |
| -------------------- | ------------------------------------------------------------------------------------------------------------------ |
| _description_        | Unique account description freely created by the user                                                              |
| _unique_             | Determines the control of the uniqueness of accounts of this classification in the system                          |
| _available\_balance_ | Determines whether every account in this classification will have the automatically created available balance type |
| _pending\_balance_   | Determines whether every account in this classification will have the automatically created pending balance type   |
| _blocked\_balance_   | Determines whether every account in this classification will have the automatically created blocked balance type   |

{% hint style="info" %}
<mark style="color:blue;">Notice:</mark>

* <mark style="color:blue;">once created an account rule description cannot be deleted</mark>
* <mark style="color:blue;">a description set as unique FALSE cannot be updated to unique TRUE</mark>
* <mark style="color:blue;">a description set as available\_balance TRUE cannot be updated to FALSE</mark>
* <mark style="color:blue;">a description set as pending\_balance TRUE cannot be updated to FALSE</mark>
* <mark style="color:blue;">a description set as blocked\_balance TRUE cannot be updated to FALSE</mark>
{% endhint %}

Example of creating or updating rules:

```json
PUT /account_rules

{
  "data": [
    {
      "description": "digital_account",
      "unique": false,
      "available_balance": true,
      "pending_balance": true,
      "blocked_balance": true
    }
  ]
}
```

## Account Rules Query <a href="#account-rules-query" id="account-rules-query"></a>

The GET /account\_rules method is used to query the rules.

Rules query example:

```json
GET /account_rules
```

Example response:

```json
{
  "data": [
    {
      "description": "digital_account",
      "unique": false,
      "available_balance": true,
      "pending_balance": true,
      "blocked_balance": true
    }
  ]
}
```
