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

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

    @TestCase(name = "Call API retention-mortgages-event to WSO2", environments = {TST1, PPE})
    public void postRetentionMortgagesEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromMortgagesToCvm(
                        RETENTION_MORTGAGES_EVENT_PATH, false,
                        "{\n" +
                                "  \"accountActive\": 2,\n" +
                                "  \"amountOutstandingPrincipal\": 968887,\n" +
                                "  \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                                "  \"contractId\": \"HY19022100\",\n" +
                                "  \"currentLtv\": 48.66,\n" +
                                "  \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"fixation\": 0,\n" +
                                "  \"interestRate\": 3.5,\n" +
                                "  \"numberInstalmentsPaid\": 20,\n" +
                                "  \"offsetFlag\": true,\n" +
                                "  \"ppiFlag\": false,\n" +
                                "  \"productType\": \"PRU\\u017dN\\u00c1 FIXN\\u00cd HYPOT\\u00c9KA\",\n" +
                                "  \"realEstateStateFlag\": null,\n" +
                                "  \"redemptionAccountType\": \"TU\",\n" +
                                "  \"remainingRepaymentTime\": 284,\n" +
                                "  \"retentionFlag\": false,\n" +
                                "  \"retentionInstallmentAmount\": 4448.26,\n" +
                                "  \"retentionInterestRate\": 2.34,\n" +
                                "  \"uniPtKey\": \"" + harness.getConfig("cvm.client.uniptkey") + "\"\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");
    }
}

