local QBCore = exports['qb-core']:GetCoreObject()

RegisterNetEvent('qb-vehicletuning:server:SaveVehicleProps', function(vehicleProps)
    ExecuteSql("UPDATE `player_vehicles` SET mods = '"..json.encode(vehicleProps).."' WHERE plate = '"..vehicleProps.plate.."'")
end)

-------------------------------- 

RegisterServerEvent('hp_mechanic:SaveVehicleProps')
AddEventHandler('hp_mechanic:SaveVehicleProps', function(vehicleProps)
	if Config.AutoSQLSave then 
        ExecuteSql("UPDATE `player_vehicles` SET mods = '"..json.encode(vehicleProps).."' WHERE plate = '"..vehicleProps.plate.."'")
    end
end)

-------------------------------- 

function nofity(source,text)
    TriggerClientEvent('QBCore:Notify', source, text)
end

-------------------------------- 

function getidentifier(xPlayer)
	hex = xPlayer.PlayerData.citizenid
	return hex
end

-------------------------------- 

function ExecuteSql(query)
    local IsBusy = true
    local result = nil
    if Config.Mysql == "oxmysql" then
        if MySQL == nil then
            exports.oxmysql:execute(query, function(data)
                result = data
                IsBusy = false
            end)
            -------------------------------- 
        else
            MySQL.query(query, {}, function(data)
                result = data
                IsBusy = false
            end)
        end
        -------------------------------- 
    elseif Config.Mysql == "ghmattimysql" then
        exports.ghmattimysql:execute(query, {}, function(data)
            result = data
            IsBusy = false
        end)
    elseif Config.Mysql == "mysql-async" then   
        MySQL.Async.fetchAll(query, {}, function(data)
            result = data
            IsBusy = false
        end)
        -------------------------------- 
    end
    while IsBusy do
        Citizen.Wait(0)
    end
    return result
end