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 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 web-loan-po-trigger to WSO2 and assert response parameters")
public class ApiWebLoanPoTrigger {

    public static final String WEB_LOAN_PO_TRIGGER_PATH = "cvm.cluster/web-loan-po-trigger/1.0.0";

    @TestCase(name = "Call API web-loan-po-trigger to WSO2", environments = {TST1, PPE})
    public void postWebLoanPoTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(WEB_LOAN_PO_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"version\": 1,\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"inputs\": {\n" +
                                "    \"configurationEventName\": \"PENNY_PAYMENT_WAITING/CC\",\n" +
                                "    \"stateId\": 65,\n" +
                                "    \"stateName\": \"PENNY_PAYMENT_WAITING\",\n" +
                                "    \"transactionId\": 28295,\n" +
                                "    \"phoneNumber\": \"+420776132887\",\n" +
                                "    \"loanAmount\": 345000,\n" +
                                "    \"installmentCount\": 58,\n" +
                                "    \"insuranceFlag\": true,\n" +
                                "    \"interestRate\": 5.9,\n" +
                                "    \"emailAddress\": \"michael.cihak@moneta.cz\",\n" +
                                "    \"businessName\": \"Jaromír Marek\",\n" +
                                "    \"firstName\": \"Jaromír\",\n" +
                                "    \"surname\": \"Marek\",\n" +
                                "    \"ico\": \"16096355\",\n" +
                                "    \"appKey\": \"62672661\",\n" +
                                "    \"appDate\": \"2021-08-17T11:06:26.000+02:00\",\n" +
                                "    \"wfId\": \"CLCH_0000005348\",\n" +
                                "    \"channel\": \"BROKER_APP\",\n" +
                                "    \"linkSaveReturn\": null\n" +
                                "  }\n" +
                                "}\n")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

}

