# Configuration

## Fetching Players' Email Addresses

This document shows how to call the `GetPlayerEmail` export from the `kibra-smartpad` resource in your FiveM scripts. Simply copy and paste the examples below into your server or client scripts.

***

### Server-Side Usage

```lua
-- In your other server script:
local playerServerId = source -- or any valid server ID
local email = exports['kibra-smartpad']:GetPlayerEmail(playerServerId)

if email ~= 'notFound' then
    print(('Player %d email: %s'):format(playerServerId, email))
else
    print(('No email configured for player %d'):format(playerServerId))
end
```

### Client-Side Usage

Since the export is exposed to the client without parameters, you can retrieve the local player’s email directly:

```lua
-- client.lua
local email = exports['kibra-smartpad']:GetPlayerEmail()
if email ~= 'notFound' then
    print('My email:', email)
else
    print('Email not set')
end
```

***

## StartMiniGame Usage

Use the `StartMiniGame` export in any script where you want to trigger the minigame (like a robbery or hacking).

```lua
local CloseTablet = true -- Ensures that the tablet shuts down after the minigame ends.
local CloseApp = false -- Ensures that the hack application closes after the minigame ends.
local NumderOfTrials = 5 -- Number of failures
local result = exports['kibra-smartpad']:StartMiniGame(CloseTablet, CloseApp, NumderOfTrials)

if result then
    -- Minigame success
else
    -- Minigame failed
end
```

***

## Creating New Mail Records

You can create and send a new mail entry using the `CreateNewMail` export. For example, register a server command:

```lua
RegisterCommand('testmail', function(source, args)
    local Receiver = 'boruhan.naster@0resmon.com'
    local MailContent = {
        subject = 'Urgent: You Have Unpaid Debts',
        message = "Hello, you have unpaid invoices to our mechanical company. We kindly ask you to pay.",
    }
    local From_Name = 'Los Santos Mechanic'
    local From = 'lossantos@0resmon.com'
    local Type = 0
    exports['kibra-smartpad']:CreateNewMail(Receiver, MailContent, From_Name, From, Type)
end)
```

* **Receiver** (`string`): The recipient's email address.
* **MailContent** (`table`): A table with `subject` and `message` keys.
* **From\_Name** (`string`): The display name of the sender.
* **From** (`string`): The sender's email address.
* **Type** (`number`): A numeric identifier for mail type (e.g., `0` for normal mail).

*Copy and paste these snippets to integrate email retrieval and creation quickly!*

## Custom Create Invoice

This export allows you to create and send a bill (invoice) to a player through the in-game tablet.

```lua
exports["kibra-smartpad"]:CreateNewBill(identifier, dueDate, products, status, note, jobName)
```

#### 📌 Parameters

| Parameter    | Type   | Description                                                                      |
| ------------ | ------ | -------------------------------------------------------------------------------- |
| `identifier` | string | The target player's unique ID (Steam or Rockstar license).                       |
| `dueDate`    | string | The bill's due date. Must be in the format `"YYYY-MM-DD"`, e.g., `"2025-06-29"`. |
| `products`   | table  | A list of products or services included in the bill. See format below.           |
| `status`     | number | Bill status: `0` for **Pending**, `1` for **Paid**.                              |
| `note`       | string | Optional note added to the bill, e.g., `"Please pay your invoice."`              |
| `jobName`    | string | The job of the player creating the bill (e.g., `"mechanic"` or `"police"`).      |

Place events, exports or functions that hide and open your border within these functions.

#### Example Usage

```lua
RegisterCommand('testbill', function(source)
    local Player = Resmon.Lib.GetPlayerFromSource(source)

    local DueDate = '2025-06-29'

    local Products = {
        {
            Description = 'Car Repair',
            Quantity = 1,
            Price = 1000
        }
    }

    local Status = 0 -- Pending
    local Note = 'Please pay your invoice.'

    exports["kibra-smartpad"]:CreateNewBill(
        Player.identifier,
        DueDate,
        Products,
        Status,
        Note,
        Player.job.name
    )
end)
```

## Fetching Players' Email Addresses

This document shows how to call the `GetPlayerEmail` export from the `kibra-smartpad` resource in your FiveM scripts. Simply copy and paste the examples below into your server or client scripts.

***

### Server-Side Usage

```lua
-- In your other server script:
local playerServerId = source -- or any valid server ID
local email = exports['kibra-smartpad']:GetPlayerEmail(playerServerId)

if email ~= 'notFound' then
    print(('Player %d email: %s'):format(playerServerId, email))
else
    print(('No email configured for player %d'):format(playerServerId))
end
```

### Client-Side Usage

Since the export is exposed to the client without parameters, you can retrieve the local player’s email directly:

```lua
-- client.lua
local email = exports['kibra-smartpad']:GetPlayerEmail()
if email ~= 'notFound' then
    print('My email:', email)
else
    print('Email not set')
end
```

*Copy and paste these snippets to integrate email retrieval quickly!*

## How to Use GiveTablet Function on Server Side

This function allows you to **give a unique SmartPad tablet** to a player in your FiveM server, with an automatically generated serial number.

### Usage

You can trigger this function from a server-side command, admin menu, or any other server script.

#### Example: Using with a Command

```lua
RegisterCommand('givetablet', function(source, args)
    exports['kibra-smartpad']:GiveTablet(source)
end)
```

## GetPlayerUnpaidInvoices

### Description

Retrieves all unpaid invoices for a given player from the **kibra-smartpad** resource.

### Usage

```lua
-- In a server-side script
local source = source -- FiveM player source ID
local unpaidInvoices = exports['kibra-smartpad']:GetPlayerUnpaidInvoices(source)
```

### Parameters

* `source` *(number)*: The server ID of the player whose unpaid invoices you wish to fetch.

### Returns

* *(table)*: An array of invoice objects. Each object contains:
  * `id` *(number)*: Invoice identifier.
  * `amount` *(number)*: Amount due.
  * `dueDate` *(string)*: Due date in ISO format (`YYYY-MM-DD`).
  * `issuedDate` *(string)*: Date the invoice was issued.
  * `status` *(string)*: Invoice status (`"unpaid"`).

### Example

```lua
-- Example: Check a player's unpaid invoices and send a chat message
RegisterCommand('checkInvoices', function(source, args, rawCommand)
    local invoices = exports['kibra-smartpad']:GetPlayerUnpaidInvoices(source)

    if #invoices > 0 then
        for _, invoice in ipairs(invoices) do
            TriggerClientEvent('chat:addMessage', source, {
                args = {
                    string.format(
                        'Invoice #%d: $%0.2f due on %s',
                        invoice.id,
                        invoice.amount,
                        invoice.dueDate
                    )
                }
            })
        end
    else
        TriggerClientEvent('chat:addMessage', source, {
            args = { 'You have no unpaid invoices!' }
        })
    end
end, false)
```

### Notes

* This export must be called from a **server-side** context.
* Ensure the `kibra-smartpad` resource is started **before** invoking this export.
