/*
 * This file is a part of the SteamWar software.
 *
 * Copyright (C) 2022  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.tablist;

import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.util.GameProfile;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import lombok.Getter;
import net.kyori.adventure.text.Component;

import java.util.List;
import java.util.UUID;

public interface TablistPart {
    String sortKey();
    void print(Chatter viewer, Player player, List<Item> tablist, List<Item> direct);

    @Getter
    class Item {
        private final UUID uuid;
        private final Component displayName;
        private final List<GameProfile.Property> properties;

        public Item(UUID uuid, String displayName, List<GameProfile.Property> properties) {
            this.uuid = uuid;
            this.displayName = Chatter.SERIALIZER.deserialize(displayName);
            this.properties = properties;
        }

        public Item(Player player) {
            this(player, false);
        }

        public Item(Player player, boolean sameTeam) {
            this.uuid = player.getUniqueId();
            UserPerm.Prefix prefix = SteamwarUser.get(player.getUniqueId()).prefix();
            if (prefix == UserPerm.emptyPrefix && sameTeam) {
                this.displayName = Chatter.SERIALIZER.deserialize("§f" + player.getUsername());
            } else {
                this.displayName = Chatter.SERIALIZER.deserialize(prefix.getColorCode() + player.getUsername());
            }
            this.properties = player.getGameProfileProperties();
        }
    }
}
