package com.oguerreiro.resilient.activity;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.spi.LoggingEventBuilder;

public class GenericResult implements ActivityResult, TaskResult {
	private static final String LOG_IDENT = "     ";
	private WorkResultEnum result;
	private List<String> errors = new ArrayList<String>();
	
	public GenericResult(WorkResultEnum result) {
		this.result=result;
	}
	
	public static GenericResult create(WorkResultEnum result) {
		return new GenericResult(result);
	}
	
	@Override
	public WorkResultEnum getWorkResult() {
		return result;
	}

	public void addError(String error) {
		this.errors.add(error);
	}
	
	public GenericResult errors(List<String> errors) {
		this.addErrors(errors);
		return this;
	}
	
	public void addErrors(List<String> errors) {
		this.errors.addAll(errors);
	}
	
	@Override
	public List<String> getErrors() {
		return this.errors;
	}
	
	public void logErrrors(LoggingEventBuilder log) {
		log.log("Errors collected in Activity/Task processing: ");
		for (String error : this.errors) {
			log.log(LOG_IDENT + error);
		}
	}
}
