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 web-loan-po-event to WSO2 and assert response parameters")
public class ApiWebLoanPoEvent {

    public static final String WEB_LOAN_PO_EVENT_PATH = "cvm.cluster/web-loan-po-event/1.0.0";

    @TestCase(name = "Call API web-loan-po-event to WSO2", environments = {TST1, PPE})
    public void postWebLoanPoEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                        WEB_LOAN_PO_EVENT_PATH, false,
                        "{\n" +
                                "  \"appDate\": \"2021-08-23T16:14:16+02:00\",\n" +
                                "  \"appKey\": \"62673241\",\n" +
                                "  \"businessName\": \"Jaromír Musil\",\n" +
                                "  \"channel\": \"BROKER_APP\",\n" +
                                "  \"emailAddress\": \"michael.cihak@moneta.cz\",\n" +
                                "  \"firstName\": \"Jaromír\",\n" +
                                "  \"ico\": \"01133063\",\n" +
                                "  \"installmentCount\": 81,\n" +
                                "  \"insuranceFlag\": true,\n" +
                                "  \"interestRate\": 5.9,\n" +
                                "  \"loanAmount\": 286000,\n" +
                                "  \"phoneNumber\": \"+420776132887\",\n" +
                                "  \"stateId\": 65,\n" +
                                "  \"stateName\": \"PENNY_PAYMENT_WAITING\",\n" +
                                "  \"surname\": \"Musil\",\n" +
                                "  \"transactionId\": 28326,\n" +
                                "  \"wfId\": \"CLCH_0000005356\"\n" +
                                "}\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");
    }
}

