package cz.moneta.test.regression.transactional.payments.cashless.wso2;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.dsl.payment_engine.model.GetAcctsBalancesResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;

@TestScenario(name = "Regression tests for WSO2 EI services. Only assumed responses are controlled")
public class Wso2EiServices {

    String TOKEN_UFO;
    String TOKEN_HUB;
    String accountId;

    @BeforeAll
    void testSetUp(Harness harness) {
        TOKEN_UFO = harness.tasks().wso2().authorization().getToken("UFO");
        TOKEN_HUB = harness.tasks().wso2().authorization().getToken("HUB");
        accountId = harness.getConfig("payments_cashless.wso2ei.account");
    }

    @Disabled ("Not currently maintained.")
    @TestCase(name = "Get transaction for verification - ICB_GetTITTranAuth_TIFv1", environments = {Environment.TST1, Environment.PPE})
    void getTransactionForVerification(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/ICB_GetTITTranAuth_TIFv1/001")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("USERID_L2", "GEMTEST")
                .withHeader("Authorization", TOKEN_UFO)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\n" +
                        " \"KodOM\":\"86001340\" \n" +
                        "}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("PocetCelkem");
    }

    @Disabled ("Not currently maintained.")
    @TestCase(name = "Get number of transactions for verification - GET_NUM_NVRF_TRN", environments = {Environment.TST1, Environment.PPE})
    void getNumberOfTransactionsForVerification(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_NUM_NVRF_TRN/001/")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_UFO)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\"KodOM\":\"86001340\"}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("PocetNezverifikovanychHlatkychPlateb")
                .andAssertPresent("PocetNezverifikovanychBankovnichTransakci");
    }

    @Disabled ("Not currently maintained.")
    @TestCase(name = "Get account balances - GET_ACCOUNT_BALANCES", environments = {Environment.TST1, Environment.PPE})
    void getAccountBalances(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_ACC_BALANCES/001/")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_HUB)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\n" +
                        "  \"accountIdentification\": \"" + accountId + "\"\n" +
                        "}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("dispositionBalance");
    }

    @Disabled ("Not currently maintained.")
    @TestCase(name = "Get accounts balances - GET_ACCTS_BALANCES", environments = {Environment.TST1, Environment.PPE})
    void getAccountsBalances(Harness harness) {
        GetAcctsBalancesResponse response = harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_ACCTS_BALANCES/001/")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_HUB)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\n" +
                        "  \"accountsIdentificationsList\": [\n" +
                        "    {\n" +
                        "      \"accountIdentification\": \"" + accountId + "\",\n" +
                        "      \"dispositionBalance\": \"123\"\n" +
                        "    }\n" +
                        "  ]\n" +
                        "}")
                .post()
                .andAssertStatus(200)
                .mapResponseIntoObject(GetAcctsBalancesResponse.class);

        Assertions.assertNotEquals("123", response.balancesList.get(0).getDispositionBalance());
        Assertions.assertEquals(accountId, response.balancesList.get(0).getAccountIdentification());
    }
}
