package be.fgov.ehealth.technicalconnector.tests.server.callback;

import be.fgov.ehealth.technicalconnector.tests.server.asserter.HttpAsserter;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;

import java.util.ArrayDeque;
import java.util.Deque;

public class AssertExpectationCallback extends AbstractExpectationCallback {

    public static Deque<HttpAsserter> asserters =new ArrayDeque<>();

    @Override
    public HttpResponse handle(HttpRequest httpRequest) {
        try {
            return asserters.poll().assertSession(httpRequest);
        } catch (Exception e) {
            return internalError(e.getMessage(), e);
        }
    }

    public static void addAsserter(HttpAsserter asserter) {
        asserters.add(asserter);
    }

    public static void reset() {
        asserters.clear();
    }
}
