---@meta sculk
-- luacheck: ignore
-- Sculk AC integrator SDK: LuaLS type annotations for every server export (docs/engine.md section 8, docs/hooks.md).
-- Copy this file into your resource or point LuaLS at it (`workspace.library`). It is a definitions file: it does
-- nothing at runtime and is never loaded by FiveM.
--
-- Every export is server-side and returns `true` on success or `false, reason` on bad input. Nothing here can raise
-- a detection's ceiling or punish a player directly.

---@class SculkCoords
---@field x number
---@field y number
---@field z number

---@alias SculkAction 'log'|'warn'|'kick'|'ban_temp'|'ban_perm'
---@alias SculkClass 'deterministic'|'strong'|'statistical'|'client'|'prevention'|'tool'

---One argument of a protected event (protectEvent schema).
---@class SculkArgSpec
---@field type? 'number'|'string'|'boolean'|'table'|'any'
---@field optional? boolean
---@field integer? boolean
---@field positive? boolean
---@field min? number
---@field max? number
---@field maxLen? integer   longest string, in bytes
---@field maxKeys? integer  most keys in a table

---@class SculkProtectOpts
---@field serverOnly? boolean        the event must never come from a client (event.serverOnly)
---@field rate? boolean|integer      count the calls per player (event.rate); an integer is the per-second limit
---@field replay? boolean            the first argument carries a nonce `{ n = '<string>' }` (event.replay)
---@field requires? string           an integrator window kind that must be open (event.precondition)
---@field near? SculkCoords|table    where the player must be (event.precondition)

---@alias SculkHookTier 'observe'|'review'|'enforce'

---A hit as a detection hook sees it (contract 0.15.0 SdkDetection): a copy, editing it changes nothing.
---@class SculkDetection
---@field detection string             detection id, e.g. 'move.teleport'
---@field class SculkClass
---@field tier SculkHookTier          observe: only recorded; review: a warn (staff queue); enforce: cancels, kicks or bans
---@field action 'none'|'log'|'cancel'|'warn'|'kick'|'ban_temp'|'ban_perm'  what Sculk does with this hit if no hook suppresses it
---@field source integer               the player's server id
---@field ref string                   the player ref Sculk uses on the dashboard (p<hex>)
---@field at integer                   unix milliseconds of the hit
---@field observed? number
---@field threshold? number
---@field measured? table<string, number>  the raw values the detection compared (obs.measured)
---@field opens_case boolean           this hit opens or adds to a case
local SculkDetection = {}

---Add a note (at most 200 characters) to the hit. Always allowed; audited. Works only while your hook runs.
---@param text string
---@return boolean ok
function SculkDetection.annotate(text) end

---Ask Sculk not to act on this hit. Honoured only when your resource has `add_ace resource.<name> sculk.hooks allow`,
---`tier` is 'observe' or 'review', the detection is not a never-bypass one (honeypots, tamper.*), and the reason is
---3 to 200 characters. A suppressed hit is still recorded (exempt 'hook'): no strike, no case, no action. Every
---attempt is audited. Works only while your hook runs.
---@param reason string
---@return boolean honoured
function SculkDetection.suppress(reason) end

---@alias SculkDetectionHook fun(detection: SculkDetection)

---@class SculkHookOpts
---@field detections? string[]  at most 32: exact ids, or a prefix ending in '.' ('move.')

---@class SculkExports
local SculkExports = {}

---@param src integer
---@param coords? SculkCoords  where the player is allowed to land
---@param ms? integer          default 5000, at most 60000
---@return boolean ok
---@return string? reason
function SculkExports:allowTeleport(src, coords, ms) end

---@param src integer
---@param ms? integer default 5000, at most 600000
---@return boolean ok
---@return string? reason
function SculkExports:allowInvincible(src, ms) end

---@param src integer
---@param amount? number health points
---@return boolean ok
---@return string? reason
function SculkExports:allowHeal(src, amount) end

---@param src integer
---@return boolean ok
---@return string? reason
function SculkExports:allowRevive(src) end

---@param src integer
---@param on boolean
---@return boolean ok
---@return string? reason
function SculkExports:cameraSession(src, on) end

---@param src integer
---@param mult number  speed multiplier, above 0 and at most 100
---@param ms? integer
---@return boolean ok
---@return string? reason
function SculkExports:allowSpeed(src, mult, ms) end

---@param src integer
---@param hash integer weapon hash (signed or unsigned)
---@return boolean ok
---@return string? reason
function SculkExports:allowWeapon(src, hash) end

---Registers the CALLING resource as an entity spawner (any argument is ignored).
---@return boolean ok
---@return string? reason
function SculkExports:registerEntitySpawner() end

---@param src integer
---@param model integer
---@param n? integer 1-256, default 1
---@return boolean ok
---@return string? reason
function SculkExports:allowEntity(src, model, n) end

---@param src integer
---@param account string  1-64 characters, e.g. 'bank'
---@param delta number
---@param reason? string
---@return boolean ok
---@return string? reason
function SculkExports:trackMoney(src, account, delta, reason) end

---@param src integer
---@param item string
---@param delta integer
---@param reason? string
---@return boolean ok
---@return string? reason
function SculkExports:trackItem(src, item, delta, reason) end

---Only the resource that owns the event may mark it (docs/engine.md section 8).
---@param name string
---@param schema? SculkArgSpec[]
---@param opts? SculkProtectOpts
---@return boolean ok
---@return string? reason
function SculkExports:protectEvent(name, schema, opts) end

---@param src integer
---@param kind string
---@param data? table
---@param ms? integer default 5000
---@return boolean ok
---@return string? reason
function SculkExports:expect(src, kind, data, ms) end

---@param src integer
---@param id? string|integer  nil clears the character
---@param name? string
---@return boolean ok
---@return string? reason
function SculkExports:setCharacter(src, id, name) end

---@param src integer
---@param id string detection id
---@return boolean excused
---@return string? reason
function SculkExports:isExcused(src, id) end

---A custom detection (class strong, warn after 3 samples in 60 s by default).
---@param src integer
---@param id string  '<resource>.<check>', not a registry id
---@param evidence? table
---@return boolean accepted
---@return string? reason
function SculkExports:flag(src, id, evidence) end

---G2.7: called synchronously inside every hit of a matching detection, before Sculk acts on it. At most 8 hooks per
---resource; a stopped resource's hooks are removed. An error or a callback over 2 ms is logged and ignored.
---@param cb SculkDetectionHook
---@param opts? SculkHookOpts
---@return integer|false handle
---@return string? reason 'bad_callback'|'bad_filter'|'no_invoking_resource'|'too_many_hooks'|'hooks_unavailable'
function SculkExports:onDetection(cb, opts) end

---Remove one of your own hooks.
---@param handle integer
---@return boolean ok
---@return string? reason 'bad_handle'|'unknown_handle'|'not_yours'|'hooks_unavailable'
function SculkExports:offDetection(handle) end

---@class CfxExports
---@field sculk SculkExports
