-- MSW_VehicleFilter.lua
-- Beschränkt Payload-Dämpfung (und andere optionale Logiken) auf bestimmte Fahrzeuge.
-- Trage hier die Script-Namen deiner Fahrzeuge ein, z. B. "SemiTruckBox" (ohne "Base.").
-- Modus:
--  - "whitelist": Nur Fahrzeuge in Vehicles werden berücksichtigt.
--  - "blacklist": Alle außer den hier gelisteten werden berücksichtigt.
--  - "all":       Keine Einschränkung.

MSW_VehicleFilter = {
    Mode = "whitelist",
    Vehicles = {
        "SemiTruckBox",
        "SemiTruckBox_mil",
        --"SemiTruck",
        --"SemiTruck_mil",
        --"SemiTruckLite",
        "SemiTrailerVan_mil",
        "SemiTrailerVan",
        --"SemiTrailerLowBed", 
    },
    MaxMassCaps = {
        SemiTrailerVan_mil = 850,
        SemiTrailerVan = 850,
    }
}

local function normalizeVehicleScriptName(name)
    if type(name) ~= "string" then
        return nil
    end

    local normalized = name:gsub("^%s+", ""):gsub("%s+$", "")
    if normalized == "" then
        return nil
    end

    return (normalized:gsub("^[^%.]+%.", ""))
end

-- Hilfsfunktionen für andere Module (optional)
function MSW_VehicleFilter.isListed(name)
    local shortName = normalizeVehicleScriptName(name)
    if not shortName then return false end

    for _, v in ipairs(MSW_VehicleFilter.Vehicles or {}) do
        if normalizeVehicleScriptName(v) == shortName then return true end
    end
    return false
end

function MSW_VehicleFilter.matchesScript(script)
    if not script then return false end

    local shortName = script.getName and script:getName() or nil
    if MSW_VehicleFilter.isListed(shortName) then return true end

    local fullName = script.getFullName and script:getFullName() or nil
    return MSW_VehicleFilter.isListed(fullName)
end

function MSW_VehicleFilter.getMaxMassCap(name)
    local shortName = normalizeVehicleScriptName(name)
    if not shortName then return nil end

    local caps = MSW_VehicleFilter.MaxMassCaps or {}
    for key, value in pairs(caps) do
        if normalizeVehicleScriptName(key) == shortName then
            return tonumber(value)
        end
    end

    return nil
end