/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2026 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.velocitycore.util;

import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserConfig;
import lombok.experimental.UtilityClass;

import java.util.HashMap;
import java.util.Map;

@UtilityClass
public class SteamwarPrefix {
    private static final String PREFIX_MODE_CONFIG = "chatprefix";
    private static final String PREFIX_MODE_SW = "SW";

    private static final Map<SteamwarUser, Boolean> usesSwPrefix = new HashMap<>();

    public static boolean usesSWPrefix(SteamwarUser user) {
        return usesSwPrefix.computeIfAbsent(user, u -> PREFIX_MODE_SW.equals(UserConfig.getConfig(u.getId(), PREFIX_MODE_CONFIG)));
    }

    public static void setSWPrefix(SteamwarUser user, boolean preferSW) {
        UserConfig.updatePlayerConfig(user.getId(), PREFIX_MODE_CONFIG, preferSW ? PREFIX_MODE_SW : null);
        usesSwPrefix.put(user, preferSW);
    }

    public static void clearCache() {
        usesSwPrefix.clear();
    }
}
