package thb.jeanluc.adventure.io;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

/**
 * Simple in-memory {@link GameIO} for tests: queued inputs, captured outputs.
 */
public class TestIO implements GameIO {

    private final Deque<String> inputs = new ArrayDeque<>();
    private final List<String> outputs = new ArrayList<>();

    public TestIO enqueue(String line) {
        inputs.add(line);
        return this;
    }

    public List<String> outputs() {
        return outputs;
    }

    public String lastOutput() {
        return outputs.isEmpty() ? null : outputs.getLast();
    }

    public String allOutput() {
        return String.join("\n", outputs);
    }

    @Override
    public String readLine() {
        return inputs.pollFirst();
    }

    @Override
    public void print(thb.jeanluc.adventure.io.text.StyledText text) {
        outputs.add(text.plainText());
    }
}
