-----------------------------------------------------------------------------------------------------------------------------------------
-- VRP
-----------------------------------------------------------------------------------------------------------------------------------------
local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
vRPS = Tunnel.getInterface("vRP")
vRP = Proxy.getInterface("vRP")
-----------------------------------------------------------------------------------------------------------------------------------------
-- CONNECTION
-----------------------------------------------------------------------------------------------------------------------------------------
Hensa = {}
Tunnel.bindInterface("police", Hensa)
vSERVER = Tunnel.getInterface("police")
-----------------------------------------------------------------------------------------------------------------------------------------
-- VARIABLES
-----------------------------------------------------------------------------------------------------------------------------------------
local InPrison = false
-----------------------------------------------------------------------------------------------------------------------------------------
-- POLICE:OPEN
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNetEvent("police:Open")
AddEventHandler("police:Open", function()
	local Ped = PlayerPedId()
	if not IsPedSwimming(Ped) then
		if LocalPlayer["state"]["Policia"] then
			SendNUIMessage({ action = "openSystem" })
			TriggerEvent("dynamic:Close")
			SetNuiFocus(true, true)

			if not IsPedInAnyVehicle(Ped) then
				vRP.CreateObjects("amb@code_human_in_bus_passenger_idles@female@tablet@idle_a", "idle_a", "prop_cs_tablet", 49, 28422, -0.05, 0.0, 0.0, 0.0, 0.0, 0.0)
			end
		end
	end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- INITPRISON
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("InitPrison", function(data)
	vSERVER.InitPrison(data["passaporte"], data["servicos"], data["multas"], data["texto"])
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- INITFINE
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("InitFine", function(data)
	vSERVER.InitFine(data["passaporte"], data["multas"], data["texto"])
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- ANNOUNCE
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("Announce", function(data)
	vSERVER.Announce(data["Title"], data["Seconds"], data["Text"])
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- UPDATEPORT
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("UpdatePort", function(data)
	vSERVER.UpdatePort(data["passaporte"])
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- SEARCHUSER
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("SearchUser", function(data, cb)
	cb({ result = vSERVER.SearchUser(data["passaporte"]) })
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- POLICE:UPDATE
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNetEvent("police:Update")
AddEventHandler("police:Update", function(action, data)
	SendNUIMessage({ action = action, data = data })
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- CHECKPRISON
-----------------------------------------------------------------------------------------------------------------------------------------
exports("checkPrison", function()
	return InPrison
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- SYNC
-----------------------------------------------------------------------------------------------------------------------------------------
function Hensa.Sync(Teleport,Status)
	if Teleport then
		if Status then
			SetEntityCoords(PlayerPedId(),SpawnPrison[1],SpawnPrison[2],SpawnPrison[3],1,0,0,0)
		else
			SetEntityCoords(PlayerPedId(),BackPrison[1],BackPrison[2],BackPrison[3],1,0,0,0)
		end
	end

	InPrison = Status
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- CLOSESYSTEM
-----------------------------------------------------------------------------------------------------------------------------------------
RegisterNUICallback("closeSystem", function()
	SetNuiFocus(false, false)
	SetCursorLocation(0.5, 0.5)
	SendNUIMessage({ action = "closeSystem" })
	vRP.Destroy("one")
end)