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-mortgages-retention-event to WSO2 and assert response parameters")
public class ApiWebMortgagesRetentionEvent {

    public static final String WEB_MORTGAGES_RETENTION_EVENT_PATH = "cvm.cluster/web-mortgages-retention-event/1.0.0";

    @TestCase(name = "Call API web-mortgages-retention-event to WSO2", environments = {TST1, PPE})
    public void postWebMortgagesRetentionEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCblToCvm(
                        WEB_MORTGAGES_RETENTION_EVENT_PATH, false,
                        "{\n" +
                                "  \"RC\": \"9361283074\",\n" +
                                "  \"bankRefinancing\": \"OTHER\",\n" +
                                "  \"email\": \"marketa@mikesovi.com\",\n" +
                                "  \"firstName\": \"Markéta\",\n" +
                                "  \"lastName\": \"S Other\",\n" +
                                "  \"mobilePhone\": \"+420731955939\",\n" +
                                "  \"mortgageID\": \"90000000\",\n" +
                                "  \"mortgagesCompany\": \"WHB\",\n" +
                                "  \"operationId\": \"T_0000965810101\",\n" +
                                "  \"originFinancialMeans\": \"OTHER\",\n" +
                                "  \"payOffDate\": \"2021-08-16\",\n" +
                                "  \"reason\": \"REPAY_MORTGAGE_EARLY\"\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");
    }
}

