package es.uv.dagarcos.master.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.uv.dagarcos.master.dto.RankingEntryDto;
import es.uv.dagarcos.master.repository.ShardPlayerStatsRepository;

@Service
public class RankingDashboardService {

    @Autowired
    private ShardPlayerStatsRepository statsRepository;

    public List<RankingEntryDto> getGlobalRanking() {

        return statsRepository.globalRanking()
                .stream()
                .map(row -> new RankingEntryDto(
                        (String) row[0],
                        (Long) row[1]
                ))
                .toList();
    }

    public List<RankingEntryDto> getShardRanking(String shardId) {

        return statsRepository.rankingByShard(shardId)
                .stream()
                .map(row -> new RankingEntryDto(
                        (String) row[0],
                        (Long) row[1]
                ))
                .toList();
    }
}
