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 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 web-building-savings-event to WSO2 and assert response parameters")
public class ApiWebBuildingSavingsEvent {

    @TestCase(name = "Call API web-building-savings-event to WSO2", environments = {TST1, PPE})
    public void postWebBuildingSavingsEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                "cvm.cluster/web-building-savings-event/1.0.0", false,
                "{\n" +
                        "    \"firstName\": \"Tomik\",\n" +
                        "    \"lastName\": \"Chlupatejsi\",\n" +
                        "    \"email\": \"volani.cc@moneta.cz\",\n" +
                        "    \"phoneNumber\": \"777763548\",\n" +
                        "    \"marketing\": true,\n" +
                        "    \"unsecuredCommunication\": false,\n" +
                        "    \"birthNumber\": \"1334567890\",\n" +
                        "    \"clientCheckWFID\": \"456def\",\n" +
                        "    \"screenID\": \"identity_check\",\n" +
                        "    \"exitResult\": \"OPAKOVANI_MOZNE\",\n" +
                        "    \"exitDescription\": \"nejaka chyba\",\n" +
                        "    \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\"\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");
    }
}

