local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
vRP = Proxy.getInterface("vRP")
API = {}
Tunnel.bindInterface("nation_bennys",API)
ESX = nil
 TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local using_bennys = {}
checkjob = function(source)
    local xPlayer = ESX.GetPlayerFromId(source)
    if xPlayer == nil then
        return
    end
    if xPlayer.PlayerData.job.name == "mechanic" then
        return true
    end
    return false
end
function API.checkPermission()
    checkjob(source)
end
function API.getSavedMods(vehicle_name, vehicle_plate)
    local result = exports.ghmattimysql:executeSync("SELECT * FROM owned_vehicles WHERE plate = "..vehicle_plate.."", {})
    return result[1].vehicles or {} or {}
end
function API.checkPayment(amount)
    if not tonumber(amount) then
        return false
    end
    local source = source
    local user_id = ESX.GetPlayerFromId(source)
    if not user_id.getMoney() > tonumber(amount) then
        TriggerClientEvent("notification",source,"Yeterli paranız yok.",7000)
        return false
    end
    TriggerClientEvent("notification",source,"Modificações aplicadas com <b>sucesso</b><br>Você pagou <b>$"..tonumber(amount).." dólares<b>.",7000)
    return true
end
function API.repairVehicle(vehicle, damage)
    TriggerEvent("tryreparar", vehicle)
    return true
end
function API.removeVehicle(vehicle)
    using_bennys[vehicle] = nil
    return true
end
function API.checkVehicle(vehicle)
    if using_bennys[vehicle] then
        return false
    end
    using_bennys[vehicle] = true
    return true
end
function API.saveVehicle(vehicle_name, vehicle_plate, vehicle_mods)
    exports.ghmattimysql:execute("UPDATE owned_vehicles SET vehicles = '"..json.encode(vehicle_mods).."' WHERE plate = '"..vehicle_plate.."'")
    return true
end
RegisterServerEvent("nation:syncApplyMods")
AddEventHandler("nation:syncApplyMods",function(vehicle_tuning,vehicle)
    TriggerClientEvent("nation:applymods_sync",-1,vehicle_tuning,vehicle)
end)
-- [[!-!]] vcux3MfIy8qDzcrMz8rKycbPzsvKzcnIyM7M [[!-!]] --