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 cz.moneta.test.harness.support.rest.RawRestRequest;

import java.time.LocalDateTime;
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 RTRD_ODS_GET_CARD_DEBIT_REJECTED_TRANSACTIONS_ATM to WSO2 and assert response parameters")
public class ApiRtrdOdsGetCardDebitRejectedTransactionsAtm {

    public static final String RTRD_ODS_GET_CARD_DEBIT_REJECTED_TRANSACTIONS_ATM_PATH = "cvm.cluster" +
            "/RTRD_ODS_GET_CARD_DEBIT_REJECTED_TRANSACTIONS_ATM/001";

    @TestCase(name = "Call API RTRD_ODS_GET_CARD_DEBIT_REJECTED_TRANSACTIONS_ATM to WSO2", environments = {TST1, PPE})
    public void postRtrdOdsGetCardDebitRejectedTransactionsAtm(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                        RTRD_ODS_GET_CARD_DEBIT_REJECTED_TRANSACTIONS_ATM_PATH, false,
                        "{\n" +
                                "  \"transactionDataList\": [\n" +
                                "    {\n" +
                                "      \"accountNumber\": \"\",\n" +
                                "      \"authorizationDate\": \"" + LocalDateTime.now() + "\",\n" +
                                "      \"cardNumber\": \"5351221100009987\",\n" +
                                "      \"rejectReason\": \"284\",\n" +
                                "      \"merchantCategory\": \"6011\",\n" +
                                "      \"transactionAmount\": 60000\n" +
                                "    }\n" +
                                "  ]\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");
        final String activityId = activityIds.get(0).toString();
    }

}