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 java.util.UUID;

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

@TestScenario(name = "Call API retention-mortgages-trigger to WSO2 and assert response parameters")
public class ApiRetentionMortgagesTrigger {

    public static final String RETENTION_MORTGAGES_TRIGGER_PATH = "cvm.cluster/retention-mortgages-trigger/1.0.0";

    @TestCase(name = "Call API retention-mortgages-trigger to WSO2", environments = {TST1, PPE})
    public void postRetentionMortgagesTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(RETENTION_MORTGAGES_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"version\": 1,\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"inputs\": {\n" +
                                "    \"configurationEventName\": \"CC\",\n" +
                                "    \"uniPtKey\": \"" + harness.getConfig("cvm.client.uniptkey") + "\",\n" +
                                "    \"contractId\": \"HY17008500\",\n" +
                                "    \"retentionFlag\": false,\n" +
                                "    \"realEstateStateFlag\": null,\n" +
                                "    \"redemptionAccountType\": \"BU\",\n" +
                                "    \"numberInstalmentsPaid\": 54,\n" +
                                "    \"remainingRepaymentTime\": 186,\n" +
                                "    \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                                "    \"fixation\": 0,\n" +
                                "    \"interestRate\": 3.69,\n" +
                                "    \"ppiFlag\": false,\n" +
                                "    \"productType\": \"PRUŽNÁ FIXNÍ HYPOTÉKA\",\n" +
                                "    \"currentLtv\": 28.04,\n" +
                                "    \"amountOutstandingPrincipal\": 831132,\n" +
                                "    \"accountActive\": null,\n" +
                                "    \"offsetFlag\": true,\n" +
                                "    \"retentionInstallmentAmount\": 5348.3,\n" +
                                "    \"retentionInterestRate\": 2.34,\n" +
                                "    \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\"\n" +
                                "  }\n" +
                                "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

        harness.tasks().cvm().cvmWso2().assertResponseOutputs(outputs);
    }

}

