# DEVELOPER GUIDE

### Developer Guide / API

#### Server export: `PerformBankTransaction`

This is the **official export** you can call from other resources to register movements in `sleekbank_transactions` and (optionally) move money.

**Signature**

```lua
-- resource: sleek-bank/server/server_open_functions.lua
exports["sleek-bank"]:PerformBankTransaction(
    realTransaction,  -- boolean: true = move balances + record; false = only record
    ibanFrom,         -- string: source IBAN or "" for system
    ibanTo,           -- string: target IBAN or "" for system
    amount,           -- number: positive integer (cents not supported)
    description       -- string|nil: up to 500 chars
)
```

**Behavior**

* When `realTransaction = true`:
  * If `ibanFrom` belongs to an **online** player, funds are removed via framework APIs.\
    If **offline**, the DB is updated directly.
  * Same for `ibanTo`: online → framework add; offline → DB update.
  * A row is inserted into `sleekbank_transactions` with **post‑amount** snapshots for both sides.
* When `realTransaction = false`:
  * **Only** inserts a transaction row (no money moved). Useful for logging external effects.

**Special cases**

* For **system charges/credits** use an empty IBAN for one side:
  * Bank fee: `ibanFrom = playerIban`, `ibanTo = ""`.
  * Interest credit: `ibanFrom = ""`, `ibanTo = playerIban`.

**Example: charge a player and credit a business account**

```lua
local ok = exports["sleek-bank"]:PerformBankTransaction(
  true,
  "BANK123456789012",   -- player
  "BANKFLEECABUS001",   -- business
  2500,                 -- $2,500
  "Vehicle purchase"
)
```

**Example: log a fine without moving money**

```lua
exports["sleek-bank"]:PerformBankTransaction(
  false,
  "BANK123456789012",
  "",
  500,
  "Admin note: unpaid fine recorded"
)
```

> The export does **not** return a value; it performs the operation (and emits framework notifications where applicable).

***

### Public Events (Safe to Publish)

> **Security notice**\
> For security reasons, server‑side triggers, parameter shapes, auth tokens and anti‑abuse checks are **intentionally omitted** from the public docs. If you need additional events or developer access, **open a support ticket** and we’ll provide vetted guidance for your integration.

#### Client events (receive‑only)

These events are **emitted to clients** and **do not grant write access**. It’s safe to list them publicly.

* **`sleek-bank:client:OpenBank (data)`**\
  Opens the banking UI with the current account snapshot.\
  \&#xNAN;*Payload (high‑level)*: IBAN, balance, totals, recent transactions, card status, whether the session is ATM/bank, and optional savings/loan summary.
* **`sleek-bank:client:Update (data)`**\
  Refreshes the UI with an updated account snapshot.\
  \&#xNAN;*Payload (high‑level)*: same structure as above (balance/totals/transactions).

**Result notifications (read‑only)**

The UI listens for simple **result notifications** where the payload is `1` (success) or `0` (failure). Listing these is safe; they **do not** perform actions by themselves.

* `UpdateMyIban`
* `DepositMoney`
* `WithdrawMoney`
* `TransferMoney`
* `BuyCreditCard`
* `EnterPin`
* `SetPin`
* `RequestLoan`
* `ActivateSavings`
* `SavingsDeposit`
* `SavingsWithdraw`
* `LoanCompleted`

> These are **notifications only**. Business logic runs server‑side with validation (proximity, ownership, balances, rate limits, etc.).

#### Opening the UI from other scripts

For programmatic UI access (e.g., from another resource), we provide an internal, protected integration.\
**We do not publish the server‑side entrypoint or parameters publicly.**\
👉 If your resource needs to open the bank UI, **open a support ticket** with your use case and we’ll share the appropriate, secured approach.

***

### Database

Tables are created by `sleek-bank.sql`.

#### `sleekbank_accounts`

| Column           | Type           | Notes                      |
| ---------------- | -------------- | -------------------------- |
| `identifier`     | varchar(46) PK | ESX license / QB citizenid |
| `iban`           | varchar(64) UK | Unique IBAN                |
| `balance`        | int unsigned   | Bank balance               |
| `card_pin`       | varchar(16)    | PIN (optional)             |
| `card_activated` | tinyint(1)     | 0/1                        |

#### `sleekbank_transactions`

| Column                  | Type              | Notes                           |
| ----------------------- | ----------------- | ------------------------------- |
| `id`                    | int AI PK         |                                 |
| `iban_from`             | varchar(64)       | May be `""` (system)            |
| `iban_to`               | varchar(64)       | May be `""` (system)            |
| `amount`                | int unsigned      | Positive amounts only           |
| `description`           | varchar(500)      | Optional                        |
| `date`                  | datetime          | Defaults to `CURRENT_TIMESTAMP` |
| `iban_from_post_amount` | int unsigned NULL | Balance after tx (source)       |
| `iban_to_post_amount`   | int unsigned NULL | Balance after tx (target)       |

> Indexes on `iban_from`, `iban_to`, `date` and combined (`iban_from`,`date`) / (`iban_to`,`date`) enable fast history queries.

#### `sleekbank_loans`

Tracks loans, installments, next payment time (ms), penalties, and whether requested or approved.

#### `sleekbank_savings`

Tracks savings balance, total growth from interest, and `next_interest` timestamp


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codeforge.gitbook.io/codeforge/sleek-series/sleek-banking/developer-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
