package com.loganmagnan.eventcore.managers.event.teams;

import com.loganmagnan.eventcore.EventCore;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Stream;

@Getter
@Setter
public class Team {

    private EventCore main = EventCore.getInstance();

    private String name;
    private List<UUID> allPlayers;
    private List<UUID> playingPlayers = new ArrayList<>();
    private UUID leader;

    public Team(String name, UUID leader, List<UUID> allPlayers) {
        this.name = name;
        this.leader = leader;
        this.allPlayers = allPlayers;
        this.playingPlayers.addAll(allPlayers);
    }

    public Team(String name, UUID leader, List<UUID> allPlayers, List<UUID> playingPlayers) {
        this.name = name;
        this.leader = leader;
        this.allPlayers = allPlayers;
        this.playingPlayers = playingPlayers;
    }

    public void killPlayer(UUID uuid) {
        this.playingPlayers.remove(uuid);
    }

    public Stream<Player> allPlayers() {
        return this.allPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull);
    }

    public Stream<Player> playingPlayers() {
        return this.playingPlayers.stream().map(this.main.getServer() :: getPlayer).filter(Objects :: nonNull);
    }
}
