package cz.moneta.test.regression.cvm.api.cvm;

import com.fasterxml.jackson.databind.JsonNode;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.rest.RawRestRequest;

import java.util.List;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@TestScenario(name = "Call API DIGI_REPAYMENT_PUSH_EVENT to WSO2 and assert response parameters")
public class ApiDigiRepaymentPushEvent {

    public static final String DIGI_REPAYMENT_PUSH_EVENT_PATH = "cvm.cluster/DIGI_REPAYMENT_PUSH_EVENT/001";

    @TestCase(name = "Call API DIGI_REPAYMENT_PUSH_EVENT to WSO2", environments = {TST1, PPE})
    public void postDigiRepaymentPushEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                        DIGI_REPAYMENT_PUSH_EVENT_PATH, false,
                        "{\n" +
                                "  \"amountToPay\": \"0\",\n" +
                                "  \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                                "  \"accountId\": \"0215887577\",\n" +
                                "  \"wpsId\": \"EAPA_0000000192\",\n" +
                                "  \"payOffReason\": \"X9\",\n" +
                                "  \"eventType\": \"fullRepayment\",\n" +
                                "  \"wpsState\": \"Canceled\",\n" +
                                "  \"productType\": \"LOAN\"\n" +
                                "}")
                .postExtended()
                .andAssertStatus(200);

        JsonNode body = response.extract("");
        List<Object> activityIds = response.getHeader("activityId");

        assertNotNull(body, "Not found output in response");
        assertEquals(1, activityIds.size(), "API should return activityId header");
    }
}

