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 org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;

import java.util.List;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Call API ib-udc-calc-event to WSO2 and assert response parameters")
public class ApiIbUdcCalcEvent {

    @TestCase(name = "Call API ib-udc-calc-event to WSO2", environments = {TST1, PPE})
    @Disabled
    public void postIbUdcCalcEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                "cvm.cluster/ib-udc-calc-event/1.0.0", false,
                "{\n" +
                        "    \"channelId\": \"IB\",\n" +
                        "    \"clientCif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                        "    \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                        "    \"userId\": " + harness.getConfig("cvm.client.userid") + ",\n" +
                        "    \"consolidationTotalLoanAmount\": 123.45,\n" +
                        "    \"consolidationInstalment\": 20.36,\n" +
                        "    \"consolidationInstalmentLength\": 12,\n" +
                        "    \"consolidationRpsn\": 9.99,\n" +
                        "    \"financialObligations\": [\n" +
                        "        {\n" +
                        "            \"obligationAmount\": 1234,\n" +
                        "            \"obligationType\": \"CREDIT_CARD\"\n" +
                        "        }\n" +
                        "    ],\n" +
                        "    \"formLastStepPage\": \"step3\",\n" +
                        "    \"userNotifiedAlready\": false\n" +
                        "}")
                .postExtended()
                .andAssertStatus(200);

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

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

