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 ib-loan-ntc-trigger to WSO2 and assert response parameters")
public class ApiIbLoanNtcTrigger {

    public static final String IB_LOAN_NTC_TRIGGER_PATH = "cvm.cluster/ib-loan-ntc-trigger/1.0.0";

    @TestCase(name = "Call API ib-loan-ntc-trigger to WSO2", environments = {TST1, PPE})
    public void postIbLoanNtcTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(IB_LOAN_NTC_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"version\": 1,\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"inputs\": {\n" +
                                "    \"configurationEventName\": \"CONTRACT_SIGNED\",\n" +
                                "    \"stateName\": \"CONTRACT_SIGNED\",\n" +
                                "    \"transactionId\": \"2\",\n" +
                                "    \"phoneNumber\": \"666666666\",\n" +
                                "    \"loanAmount\": 10000.50,\n" +
                                "    \"installmentCount\": 50,\n" +
                                "    \"insuranceFlag\": true,\n" +
                                "    \"interestRate\": 9.99,\n" +
                                "    \"emailAddress\": \"email\",\n" +
                                "    \"businessName\": \"name\",\n" +
                                "    \"firstName\": null,\n" +
                                "    \"surname\": null,\n" +
                                "    \"ico\": \"123456\",\n" +
                                "    \"appKey\": \"xxx\",\n" +
                                "    \"appDate\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "    \"channel\": \"IB\",\n" +
                                "    \"cif\": \"" + harness.getConfig("cvm.client.cif") + "\"\n" +
                                "  }\n" +
                                "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

}

