package com.telephoners.krakyournet.ctf.resources;

import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Singleton
@Path(value = "/solutions")
@Produces(MediaType.APPLICATION_JSON)
public class SolutionsResource
{

    @GET
    public void get(){

    }
//    private final Repository<Team> teamsRepository;
//    private final Repository<Solution> solutionsRepository;
//    private final Repository<Task> tasksRepository;
//
//    @Inject
//    public SolutionsResource(Repository<Solution> solutionsRepository,
//                             Repository<Task> tasksRepository,
//                             Repository<Team> teamsRepository)
//    {
//        this.solutionsRepository = solutionsRepository;
//        this.teamsRepository = teamsRepository;
//        this.tasksRepository = tasksRepository;
//    }

    /*
    @POST
    @Path("/{task_level}")
    public Response submitSolution(@Auth User user,
                                   @PathParam("task_level") int taskLevel,
                                   String userFlag) throws Exception
    {
        return null;
        //todo: this should be by id

        Task task = tasksRepository.getByLevel(taskLevel);
        Flag flag = task.getFlags()
                .stream()
                .filter(taskFlag -> taskFlag.getValue().equals(userFlag))
                .findFirst()
                .orElseThrow(InvalidSolutionException::new);

        solutionsRepository.submitSolution(new Solution(teamsRepository.getTeamByUser(user), task, flag));
        return Response.ok().entity(flag).build();
    }

    @GET
    @Path("/my/completed")
    public List<Integer> getTeamCompletedTasks(@Auth User user)
    {
return null;

        return solutionsRepository.getCompletedTasks(teamsRepository.getTeamByUser(user));
    }

    @GET
    @Path("/all/completed")
    public Map<String, List<Integer>> getAllTeamsCompletedTasks(@Auth User user)
    {
        return null;

        return teamsRepository.getAll()
                .stream()
                .collect(Collectors.toMap(
                        Team::getName,
                        solutionsRepository::getCompletedTasks
                ));
    }

    @GET
    @Path("/my")
    public Map<Integer, List<Flag>> getTeamSummittedFlags(@Auth User user) {
        return null;

        Map<Integer, List<Flag>> teamSolutions = solutionsRepository.getTeamSolutions(teamsRepository.getTeamByUser(user));
        return teamSolutions;
    }

    @GET
    @Path("/all")
    public Map<String, Map<Integer, Integer>> getTeamsSolutions()
    {
        return null;

        return teamsRepository.getAll()
                .stream()
                .collect(Collectors.toMap(
                        Team::getName,
                        solutionsRepository::getPointsSum
                ));
    }*/
}
