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 ib-loan-ntc-event to WSO2 and assert response parameters")
public class ApiIbLoanNtcEvent {

    public static final String IB_LOAN_NTC_EVENT_PATH = "cvm.cluster/ib-loan-ntc-event/1.0.0";

    @TestCase(name = "Call API ib-loan-ntc-event to WSO2", environments = {TST1, PPE})
    public void postIbLoanNtcEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                        IB_LOAN_NTC_EVENT_PATH, false,
                        "{\n" +
                                "  \"stateName\": \"CONTRACT_SIGNED\",\n" +
                                "  \"transactionId\": \"2\",\n" +
                                "  \"phoneNumber\": \"666666666\",\n" +
                                "  \"loanAmount\": 10000.50,\n" +
                                "  \"installmentCount\": 50,\n" +
                                "  \"insuranceFlag\": true,\n" +
                                "  \"interestRate\": 9.99,\n" +
                                "  \"emailAddress\": \"email\",\n" +
                                "  \"businessName\": \"name\",\n" +
                                "  \"firstName\": null,\n" +
                                "  \"surname\": null,\n" +
                                "  \"ico\": \"123456\",\n" +
                                "  \"appKey\": \"xxx\",\n" +
                                "  \"appDate\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"channel\": \"IB\",\n" +
                                "  \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\"\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");
    }
}

