package es.uv.dagarcos.master.controller;

import es.uv.dagarcos.master.dto.DashboardSummaryDto;
import es.uv.dagarcos.master.dto.ShardEventTimeSeriesDto;
import es.uv.dagarcos.master.dto.ShardOverviewDto;
import es.uv.dagarcos.master.dto.ShardPlayerStatsDto;
import es.uv.dagarcos.master.dto.ShardWorldSnapshotDto;
import es.uv.dagarcos.master.service.ShardDashboardService;
import es.uv.dagarcos.master.service.ShardPlayerStatsService;
import es.uv.dagarcos.master.service.ShardWorldSnapshotService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/master")
@CrossOrigin // importante para abrir la GUI desde file://
public class DashboardShardsController {

    @Autowired
    private ShardDashboardService dashboardService;
    @Autowired 
    private ShardPlayerStatsService shardPlayerStatsService;
    @Autowired 
    private ShardWorldSnapshotService shardWorldSnapshotService;

    @GetMapping("/shards")
    public List<ShardOverviewDto> getShardsOverview() {
        return dashboardService.getShardOverview();
    }

    @GetMapping("/dashboard/summary")
    public DashboardSummaryDto getDashboardSummary() {
        return dashboardService.getSummary();
    }

    @GetMapping("/shards/{shardId}/players")
    public List<ShardPlayerStatsDto> getShardPlayers(@PathVariable String shardId) {
        return shardPlayerStatsService.getRankingForShard(shardId);
    }

    @GetMapping("/shards/{shardId}/snapshots")
    public List<ShardWorldSnapshotDto> getShardSnapshots(@PathVariable String shardId){
        return shardWorldSnapshotService.getSnapshots(shardId);
    }


    @GetMapping("/shards/{shardId}/events/timeseries")
    public List<ShardEventTimeSeriesDto> getShardEventTimeSeries(@PathVariable String shardId) {
        return dashboardService.getEventTimeSeries(shardId);
    }


}