# Update Citizen License

***

{% hint style="warning" %}
updateCitizenLicense(source, data)
{% endhint %}

Updates or creates a license record for a specific citizen in the system.

***

### Parameters

#### `source`

**Type:** `number`\
**Description:** The source player ID from which the request is initiated.

***

#### `data`

**Type:** `table`\
**Description:** Contains the citizen ID and license information to be updated or inserted.

***

### Fields within `data`

#### `data.citizenId`

**Type:** `string`\
**Required:** ✅\
**Description:** The unique identifier for the citizen whose license record is being updated or created.

***

#### `data.license`

**Type:** `table`\
**Required:** ✅\
**Description:** Contains details of the license being created or modified.

***

### Fields within `data.license`

| Field            | Type     | Required | Description                                                                        |
| ---------------- | -------- | -------- | ---------------------------------------------------------------------------------- |
| `type`           | `string` | ✅        | Type of license (e.g., `"driver"`, `"weapon"`).                                    |
| `name`           | `string` | ✅        | Name of the license.                                                               |
| `status`         | `string` | ✅        | Status of the license. Accepted values: `"approved"`, `"rejected"`, `"expired"`.   |
| `approvedBy`     | `string` | ❌        | Name of the person who approved the license. Defaults to the source player.        |
| `approvedDate`   | `string` | ❌        | Date of approval in format `"YYYY-MM-DD HH:MM:SS"`. Defaults to current date.      |
| `expirationDate` | `string` | ❌        | Expiry date in format `"YYYY-MM-DD HH:MM:SS"`. Set only if status is `"approved"`. |
| `note`           | `string` | ❌        | Additional notes or comments related to the license.                               |

***

### Returns

**Type:** `table`\
**Description:** Returns a response object indicating the result of the operation.

***

### Response Fields

| Field      | Type      | Description                                                                   |
| ---------- | --------- | ----------------------------------------------------------------------------- |
| `success`  | `boolean` | Whether the license was successfully inserted or updated.                     |
| `message`  | `string`  | A message describing the outcome (e.g., `"License updated successfully."`).   |
| `licenses` | `string`  | *(Optional)* JSON-encoded string of all licenses associated with the citizen. |

***

### Example Usage

```lua
local result = exports['kartik-mdt']:updateCitizenLicense(source, {
    citizenId = "CIT12345",
    license = {
        type = "driver",
        name = "Driver License",
        status = "approved",
        approvedBy = "Officer Smith",
        approvedDate = "2025-04-16 14:25:00",
        expirationDate = "2026-04-16 00:00:00",
        note = "First-time issue"
    }
})
```

***
