# Server

Server exports are controlled by the `exportAllowlist` in config; an empty table allows all resources to call them. Failed calls return `{ error = "..." }`.

For client-side exports see [Client](./client.mdx).

## Terminal [#terminal]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### openTerminal(source) [#openterminalsource]
    <p className="text-fd-muted-foreground text-sm">Open the MDT for a player. Runs the same setup as the <code>/mdt</code> command (job check, duty check, roster status, department/staff fetch). Shows the same access-denied toasts on failure.</p>
    ```lua
    ---@param source number Player server ID
    ---@return { ok: true }|{ error: string }
    local result = exports.vx_mdt:openTerminal(source)
    if result.error then
        -- Denied: wrong job, off-duty, suspended/fired/on-leave, etc.
    end
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### closeTerminal(source) [#closeterminalsource]
    <p className="text-fd-muted-foreground text-sm">Close the MDT for a player. Safe to call when the MDT is already closed.</p>
    ```lua
    ---@param source number Player server ID
    ---@return { ok: true }|{ error: string }
    exports.vx_mdt:closeTerminal(source)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### isTerminalOpen(source) [#isterminalopensource]
    <p className="text-fd-muted-foreground text-sm">Check whether a player currently has the MDT open. Reads the replicated <code>terminal_subscribed</code> state bag.</p>
    ```lua
    ---@param source number Player server ID
    ---@return boolean
    local open = exports.vx_mdt:isTerminalOpen(source)
    ```
</div>

## Officers [#officers]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createOfficer(identifier, depId, data) [#createofficeridentifier-depid-data]
    <p className="text-fd-muted-foreground text-sm">Create a staff record for a department.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@param depId number Department ID
    ---@param data { first_name: string, last_name: string, callsign?: string, badge_number?: string, rank_id?: number, source?: number }
    ---@return table Staff record or { error: string }
    local officer = exports.vx_mdt:createOfficer(identifier, depId, {
        first_name = "John",
        last_name = "Doe",
        callsign = "1-A",
        badge_number = "1234",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### deleteOfficer(identifier, depId) [#deleteofficeridentifier-depid]
    <p className="text-fd-muted-foreground text-sm">Soft-delete an officer (sets status to "terminated").</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@param depId number Department ID
    ---@return boolean
    local success = exports.vx_mdt:deleteOfficer(identifier, depId)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getOfficer(identifier, depId) [#getofficeridentifier-depid]
    <p className="text-fd-muted-foreground text-sm">Get officer data including permissions.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@param depId number Department ID
    ---@return table|nil Staff record or nil
    local officer = exports.vx_mdt:getOfficer(identifier, depId)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### updateOfficer(identifier, depId, data) [#updateofficeridentifier-depid-data]
    <p className="text-fd-muted-foreground text-sm">Update officer fields.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@param depId number Department ID
    ---@param data { callsign?: string, badge_number?: string, rank_id?: number, status?: string, notes?: string, certificates?: table }
    ---@return boolean
    local success = exports.vx_mdt:updateOfficer(identifier, depId, {
        callsign = "2-B",
        badge_number = "5678",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### isOfficer(source) [#isofficersource]
    <p className="text-fd-muted-foreground text-sm">Check if an online player is set up as an officer.</p>
    ```lua
    ---@param source number Player server ID
    ---@return boolean
    local isOfficer = exports.vx_mdt:isOfficer(source)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getOfficerBySource(source) [#getofficerbysourcesource]
    <p className="text-fd-muted-foreground text-sm">Get officer data for an online player.</p>
    ```lua
    ---@param source number Player server ID
    ---@return table|nil Staff record or nil
    local officer = exports.vx_mdt:getOfficerBySource(source)
    ```
</div>

## Profiles [#profiles]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getProfile(identifier) [#getprofileidentifier]
    <p className="text-fd-muted-foreground text-sm">Get a full citizen profile.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@return table|nil Profile record or nil
    local profile = exports.vx_mdt:getProfile(identifier)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### updateProfileField(identifier, field, value) [#updateprofilefieldidentifier-field-value]
    <p className="text-fd-muted-foreground text-sm">Update a specific field on a citizen profile.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@param field "dna"|"fingerprint"|"bloodtype"|"profile_image_url"
    ---@param value string New value
    ---@return boolean
    local success = exports.vx_mdt:updateProfileField(identifier, "dna", "ABC-1234")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### searchProfiles(query) [#searchprofilesquery]
    <p className="text-fd-muted-foreground text-sm">Search citizen profiles by name or identifier.</p>
    ```lua
    ---@param query string Search query
    ---@return table[] Array of profile search results
    local results = exports.vx_mdt:searchProfiles("John")
    ```
</div>

## Vehicles [#vehicles]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getVehicle(plate) [#getvehicleplate]
    <p className="text-fd-muted-foreground text-sm">Get a full vehicle record by plate.</p>
    ```lua
    ---@param plate string Vehicle plate
    ---@return table|nil Vehicle record or nil
    local vehicle = exports.vx_mdt:getVehicle("ABC123")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### setVehicleStatus(plate, status, notes?) [#setvehiclestatusplate-status-notes]
    <p className="text-fd-muted-foreground text-sm">Set the status flag on a vehicle. When <code>notes</code> is provided, it overwrites the vehicle's notes field; when omitted, existing notes are preserved.</p>
    ```lua
    ---@param plate string Vehicle plate
    ---@param status "none"|"stolen"|"seized"|"impounded"|"wanted"|"flagged"|"parked"|"out"
    ---@param notes? string Optional notes to set on the vehicle
    ---@return boolean
    local success = exports.vx_mdt:setVehicleStatus("ABC123", "stolen")
    local success = exports.vx_mdt:setVehicleStatus("ABC123", "parked", "Garage: Legion Square")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### searchVehicles(query) [#searchvehiclesquery]
    <p className="text-fd-muted-foreground text-sm">Search vehicles by plate or owner.</p>
    ```lua
    ---@param query string Search query
    ---@return table[] Array of vehicle search results
    local results = exports.vx_mdt:searchVehicles("ABC")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### registerVehicle(source, data) [#registervehiclesource-data]
    <p className="text-fd-muted-foreground text-sm">Fire-and-forget auto-register from garage bridges.</p>
    ```lua
    ---@param source number Player server ID
    ---@param data { plate: string, model_name?: string, color?: string, vehicle_class?: string, autoLinkOwner?: boolean, owner?: string }
    exports.vx_mdt:registerVehicle(source, {
        plate = "ABC123",
        model_name = "sultan",
        color = "Red",
    })
    ```
</div>

## Weapons [#weapons]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createWeapon(serial, data) [#createweaponserial-data]
    <p className="text-fd-muted-foreground text-sm">Create a weapon record if it doesn't already exist.</p>
    ```lua
    ---@param serial string Weapon serial number
    ---@param data { model?: string, owner?: string, source?: number }
    ---@return boolean
    local success = exports.vx_mdt:createWeapon("WPN-001", {
        model = "WEAPON_PISTOL",
        owner = "ABC12345",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getWeapon(serial) [#getweaponserial]
    <p className="text-fd-muted-foreground text-sm">Get a full weapon record by serial number.</p>
    ```lua
    ---@param serial string Weapon serial number
    ---@return table|nil Weapon record or nil
    local weapon = exports.vx_mdt:getWeapon("WPN-001")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### setWeaponStatus(serial, status) [#setweaponstatusserial-status]
    <p className="text-fd-muted-foreground text-sm">Set the status flag on a weapon.</p>
    ```lua
    ---@param serial string Weapon serial number
    ---@param status "none"|"stolen"|"seized"|"destroyed"|"missing"
    ---@return boolean
    local success = exports.vx_mdt:setWeaponStatus("WPN-001", "stolen")
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### registerWeapon(source, data) [#registerweaponsource-data]
    <p className="text-fd-muted-foreground text-sm">Fire-and-forget auto-register from inventory bridges.</p>
    ```lua
    ---@param source number Player server ID
    ---@param data { serial: string, model?: string, owner?: string }
    exports.vx_mdt:registerWeapon(source, {
        serial = "WPN-001",
        model = "WEAPON_PISTOL",
    })
    ```
</div>

## Properties [#properties]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getProperty(id) [#getpropertyid]
    <p className="text-fd-muted-foreground text-sm">Get a property record by ID.</p>
    ```lua
    ---@param id number Property ID
    ---@return table|nil Property record or nil
    local property = exports.vx_mdt:getProperty(1)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### searchProperties(query) [#searchpropertiesquery]
    <p className="text-fd-muted-foreground text-sm">Search properties by address.</p>
    ```lua
    ---@param query string Search query
    ---@return table[] Array of property search results
    local results = exports.vx_mdt:searchProperties("Alta St")
    ```
</div>

## BOLOs [#bolos]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createBolo(depId, data) [#createbolodepid-data]
    <p className="text-fd-muted-foreground text-sm">Create a Be On the Lookout notice.</p>
    ```lua
    ---@param depId number Department ID
    ---@param data { title: string, bolo_type?: "person"|"vehicle"|"other", author?: string }
    ---@return { id: number }|{ error: string }
    local result = exports.vx_mdt:createBolo(1, {
        title = "Suspect in white sedan",
        bolo_type = "vehicle",
        author = "Officer Smith",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### deleteBolo(boloId, depId) [#deleteboloboloid-depid]
    <p className="text-fd-muted-foreground text-sm">Delete a BOLO by ID.</p>
    ```lua
    ---@param boloId number BOLO ID
    ---@param depId number Department ID
    ---@return {}|{ error: string }
    local result = exports.vx_mdt:deleteBolo(1, 1)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### hasActiveBolo(identifier) [#hasactiveboloidentifier]
    <p className="text-fd-muted-foreground text-sm">Check if an identifier has any active BOLOs. Uses in-memory lookup for fast performance.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@return boolean
    local hasBolo = exports.vx_mdt:hasActiveBolo(identifier)
    ```
</div>

## Warrants [#warrants]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createWarrant(depId, data) [#createwarrantdepid-data]
    <p className="text-fd-muted-foreground text-sm">Create a warrant.</p>
    ```lua
    ---@param depId number Department ID
    ---@param data { title: string, warrant_type?: "arrest"|"search", author?: string }
    ---@return { id: number }|{ error: string }
    local result = exports.vx_mdt:createWarrant(1, {
        title = "Arrest warrant for John Doe",
        warrant_type = "arrest",
        author = "Judge Williams",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### deleteWarrant(warrantId, depId) [#deletewarrantwarrantid-depid]
    <p className="text-fd-muted-foreground text-sm">Delete a warrant by ID.</p>
    ```lua
    ---@param warrantId number Warrant ID
    ---@param depId number Department ID
    ---@return {}|{ error: string }
    local result = exports.vx_mdt:deleteWarrant(1, 1)
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### hasActiveWarrant(identifier) [#hasactivewarrantidentifier]
    <p className="text-fd-muted-foreground text-sm">Check if an identifier has any active warrants. Uses in-memory lookup for fast performance.</p>
    ```lua
    ---@param identifier string Citizen/state ID
    ---@return boolean
    local hasWarrant = exports.vx_mdt:hasActiveWarrant(identifier)
    ```
</div>

## Incidents [#incidents]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createIncident(depId, data) [#createincidentdepid-data]
    <p className="text-fd-muted-foreground text-sm">Create a new incident.</p>
    ```lua
    ---@param depId number Department ID
    ---@param data { title: string, author?: string, dep_type?: "law"|"ems"|"judge" }
    ---@return { id: number }|{ error: string }
    local result = exports.vx_mdt:createIncident(1, {
        title = "Traffic stop on Route 68",
        author = "Officer Smith",
    })
    ```
</div>

## Reports [#reports]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### createReport(depId, data) [#createreportdepid-data]
    <p className="text-fd-muted-foreground text-sm">Create a new report.</p>
    ```lua
    ---@param depId number Department ID
    ---@param data { title: string, author?: string, dep_type?: "law"|"ems"|"judge" }
    ---@return { id: number }|{ error: string }
    local result = exports.vx_mdt:createReport(1, {
        title = "Daily patrol report",
        author = "Officer Smith",
    })
    ```
</div>

## Toaster [#toaster]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### toastPlayer(source, data) [#toastplayersource-data]
    <p className="text-fd-muted-foreground text-sm">Send a toast notification to a single player.</p>
    ```lua
    ---@param source number Player server ID
    ---@param data { title: string, message: string, close_delay?: number, type?: "default"|"assertive"|"polite"|"warn", sound?: string }
    ---@return boolean|{ error: string }
    local result = exports.vx_mdt:toastPlayer(source, {
        title = "Dispatch",
        message = "You have been assigned to call #42",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### toastPlayers(sources, data) [#toastplayerssources-data]
    <p className="text-fd-muted-foreground text-sm">Send a toast notification to multiple players.</p>
    ```lua
    ---@param sources number[] Array of player server IDs
    ---@param data { title: string, message: string, close_delay?: number, type?: "default"|"assertive"|"polite"|"warn", sound?: string }
    ---@return boolean|{ error: string }
    local result = exports.vx_mdt:toastPlayers({1, 2, 3}, {
        title = "Alert",
        message = "Shift change in 5 minutes",
    })
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### toastDepartment(depId, data, excludeSource?) [#toastdepartmentdepid-data-excludesource]
    <p className="text-fd-muted-foreground text-sm">Send a toast notification to all online members of a department.</p>
    ```lua
    ---@param depId number Department ID
    ---@param data { title: string, message: string, close_delay?: number, type?: "default"|"assertive"|"polite"|"warn", sound?: string }
    ---@param excludeSource? number Player server ID to exclude
    ---@return boolean|{ error: string }
    local result = exports.vx_mdt:toastDepartment(1, {
        title = "BOLO Update",
        message = "New BOLO issued for white sedan",
    })
    ```
</div>

## Lookups [#lookups]

<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getCharges() [#getcharges]
    <p className="text-fd-muted-foreground text-sm">Returns all charges with categories (cached).</p>
    ```lua
    ---@return table[] Array of charges
    local charges = exports.vx_mdt:getCharges()
    ```
</div>
<br />
<div className="flex flex-col gap-2 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose">
    ### getDepartments() [#getdepartments]
    <p className="text-fd-muted-foreground text-sm">Returns a lightweight department list.</p>
    ```lua
    ---@return table[] Array of departments
    local departments = exports.vx_mdt:getDepartments()
    ```
</div>
