package api;

import Repository.SolutionsRepository;
import Repository.TasksRepository;
import Repository.TeamsRepository;
import core.FlagChecker;
import objects.Task;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * Created by gpietrus on 16.02.16.
 */
@Path(value = "/tasks")
@Produces(MediaType.APPLICATION_JSON)
public class TasksResource
{
    private TasksRepository tasksRepository;
    private TeamsRepository teamsRepository;
    private SolutionsRepository solutionsRepository;
    //todo: use injections

    @Inject
    public TasksResource(TasksRepository tasksRepository, TeamsRepository teamsRepository, SolutionsRepository solutionsRepository) {
        this.tasksRepository = tasksRepository;
        this.teamsRepository = teamsRepository;
        this.solutionsRepository = solutionsRepository;
    }

    @GET
    public List<Task> getTasks() {
        return tasksRepository.getAll();
    }

    @POST
    public boolean submitSolution(String flag) throws Exception {
        return new FlagChecker(tasksRepository, teamsRepository, solutionsRepository).checkFlag(flag);
    }

}
