package cz.moneta.test.dsl.wiremock.tasks;

import cz.moneta.test.dsl.Harness;

import cz.moneta.test.harness.support.util.Template;

public class WiremockTasks {
    private final Harness harness;

    public WiremockTasks(Harness harness) {
        this.harness = harness;
    }

    public String createMock(Template payload) {
        var response = harness.withMockServer()
                .prepareRequest()
                .withPath("/__admin/mappings")
                .withPayloadFromTemplate(payload)
                .post()
                .andAssertStatus(201);
        return response.extract("id").textValue();
    }

    public String createMock(String payload) {
        var response = harness.withMockServer()
                .prepareRequest()
                .withPath("/__admin/mappings")
                .withHeader("Content-Type", "application/json")
                .withPayload(payload)
                .post()
                .andAssertStatus(201);
        return response.extract("id").textValue();
    }

    public void deleteMock(String mockId) {
        harness.withMockServer()
                .prepareRequest()
                .withPath("/__admin/mappings/" + mockId)
                .delete()
                .andAssertStatus(200);
    }

}
