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 digi-retention-trigger to WSO2 and assert response parameters")
public class ApiDigiRetentionTrigger {

    public static final String DIGI_RETENTION_TRIGGER_PATH = "cvm.cluster/digi-retention-trigger/1.0.0";

    @TestCase(name = "Call API digi-retention-trigger to WSO2", environments = {TST1, PPE})
    public void postDigiRetentionTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(DIGI_RETENTION_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"version\": 1,\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"inputs\": {\n" +
                                "    \"configurationEventName\": \"retention/CC\",\n" +
                                "    \"eventType\": \"fullRepayment\",\n" +
                                "    \"cblSessionId\": \"" + UUID.randomUUID() + "\",\n" +
                                "    \"channel\": null,\n" +
                                "    \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                                "    \"accountId\": \"0215887577\",\n" +
                                "    \"amountToPay\": 123286,\n" +
                                "    \"payOffReason\": null,\n" +
                                "    \"productType\": \"LOAN\",\n" +
                                "    \"wpsId\": \"EAPA_0000000192\",\n" +
                                "    \"screenId\": \"SB:LOANS:REPAYMENT:VICTORY\",\n" +
                                "    \"eventTimeStamp\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\"\n" +
                                "  }\n" +
                                "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

}

