package algoLike.pull;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Component;
import pushPullRefactor.Getter;
import pushPullRefactor.Message;
import pushPullRefactor.Resource;
import pushPullRefactor.State;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.*;
@Path("/deck")
@Component
@Resource("deck")
public class Deck {
private Map.Entry<Boolean, Integer> resultByDrawingA;
private Map.Entry<Boolean, Integer> resultByDrawingB;
@State
private List<Map.Entry<Integer, Boolean>> value = new ArrayList<Map.Entry<Integer, Boolean>>();
@Path("/resultByDrawingA")
@POST
@Message({"resultByDrawingA"})
public void updateResultByDrawingA(@FormParam("resultByDrawingA") String resultByDrawingA_json) throws JsonProcessingException {
Map.Entry<Boolean, Integer> resultByDrawingA;
{
Map<String, Integer> i = new ObjectMapper().readValue(resultByDrawingA_json, HashMap.class);
resultByDrawingA = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue());
}
this.resultByDrawingA = resultByDrawingA;
this.value = this.value.subList(1, this.value.size());
}
@Path("/resultByDrawingB")
@POST
@Message({"resultByDrawingB"})
public void updateResultByDrawingB(@FormParam("resultByDrawingB") String resultByDrawingB_json) throws JsonProcessingException {
Map.Entry<Boolean, Integer> resultByDrawingB;
{
Map<String, Integer> i = new ObjectMapper().readValue(resultByDrawingB_json, HashMap.class);
resultByDrawingB = new AbstractMap.SimpleEntry<>(Boolean.parseBoolean(i.entrySet().iterator().next().getKey()), i.entrySet().iterator().next().getValue());
}
this.resultByDrawingB = resultByDrawingB;
this.value = this.value.subList(1, this.value.size());
}
@POST
public void addCard(@FormParam("num") Integer num) {
this.value.add(0, new AbstractMap.SimpleEntry<>(num, false));
}
@Produces(MediaType.APPLICATION_JSON)
@GET
@Getter
public List<Map.Entry<Integer, Boolean>> getValue() {
return value;
}
}