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

import com.fasterxml.jackson.databind.JsonNode;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.DateUtils;
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-udc-event to WSO2 and assert response parameters")
public class ApiDigiUdcEvent {

    public static final String DIGI_UDC_EVENT_PATH = "cvm.cluster/digi-udc-event/1.0.0";

    @TestCase(name = "Call API digi-udc-event to WSO2", environments = {TST1, PPE})
    public void postDigiUdcEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                        DIGI_UDC_EVENT_PATH, false,
                        "{\n" +
                                "  \"applicationKey\": 68153896,\n" +
                                "  \"channelId\": \"SB\",\n" +
                                "  \"clientCif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                                "  \"consolidationInstalment\": 3173.23,\n" +
                                "  \"consolidationRpsn\": 5.63,\n" +
                                "  \"consolidationTotalLoanAmount\": 246000,\n" +
                                "  \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"ppiFlag\": 0,\n" +
                                "  \"screenId\": \"DOCUMENTS_VERIFIED\",\n" +
                                "  \"userId\": " + harness.getConfig("cvm.client.userid") + "\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");
    }
}

