package mtsar.api;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import mtsar.processors.AnswerAggregator;
import mtsar.processors.TaskAllocator;
import mtsar.processors.WorkerRanker;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Map;
import java.util.logging.Logger;

@Singleton
@XmlRootElement
public class Process {
    public static Provider<Process> wrap(Process process) {
        return new Provider<Process>() {
            @Override
            public Process get() {
                return process;
            }
        };
    }

    protected String id;
    protected Map<String, String> options;

    protected final WorkerRanker workerRanker;
    protected final TaskAllocator taskAllocator;
    protected final AnswerAggregator answerAggregator;

    @Inject
    public Process(@Named("id") String id, @Named("options") Map<String, String> options, WorkerRanker workerRanker, TaskAllocator taskAllocator, AnswerAggregator answerAggregator, Logger logger) {
        this.id = id;
        this.workerRanker = workerRanker;
        this.taskAllocator = taskAllocator;
        this.answerAggregator = answerAggregator;
        this.options = options;
        logger.info(String.format("Allocated a Process called \"%s\" with %d option(s)", id, options.size()));
    }

    @JsonProperty
    public String getId() {
        return id;
    }

    @JsonProperty
    public Map<String, String> getOptions() {
        return options;
    }

    @JsonIgnore
    public WorkerRanker getWorkerRanker() {
        return workerRanker;
    }

    @JsonIgnore
    public TaskAllocator getTaskAllocator() {
        return taskAllocator;
    }

    @JsonIgnore
    public AnswerAggregator getAnswerAggregator() {
        return answerAggregator;
    }
}

@@ -1939,11 +1939,425 @@
 r;%0A    %7D
+%0A%0A    @JsonProperty(%22workerRanker%22)%0A    public String getWorkerRankerName() %7B%0A        return workerRanker.getClass().getName();%0A    %7D%0A%0A    @JsonProperty(%22taskAllocator%22)%0A    public String getTaskAllocatorName() %7B%0A        return taskAllocator.getClass().getName();%0A    %7D%0A%0A    @JsonProperty(%22answerAggregator%22)%0A    public String getAnswerAggregatorName() %7B%0A        return answerAggregator.getClass().getName();%0A    %7D
 %0A%7D%0A

Add Process.get{WorkerRanker,TaskAllocator,AnswerAggregator}Name