package leigh.tesseract;

import leigh.mecha.lang.Counter;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

import java.io.IOException;
import java.util.Objects;

public abstract class ResultWriterBase implements ResultWriter {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(ResultWriterBase.class);

    private final Counter<String> counter = new Counter<>();

    @Override
    public void output(String hostname, String result, int returnCode) throws IOException {
        counter.count(result);
    }

    public Counter<String> getCounter() {
        return counter;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ResultWriterBase that = (ResultWriterBase) o;
        return Objects.equals(counter, that.counter);
    }

    @Override
    public int hashCode() {
        return Objects.hash(counter);
    }

    @Override
    public String toString() {
        return "ResultWriterBase{" +
                "counter=" + counter +
                '}';
    }
}
