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.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;


@TestScenarioWithOrder(name = "Test connection to all payments cluster backends via WSO2")
public class Wso2BackendsConnection {

    String TOKEN_INTEGRATOR;
    String TOKEN_UFO;
    String TOKEN_CBL;

    @BeforeAll
    void testSetUp(Harness harness) {
        TOKEN_INTEGRATOR = harness.tasks().wso2().authorization().getToken("PAYMENTS_INTEGRATOR");
        TOKEN_UFO = harness.tasks().wso2().authorization().getToken("UFO");
        TOKEN_CBL = harness.tasks().wso2().authorization().getToken("DigitalchannelsSB_CBL");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1698")
    @TestCase(name = "Get kasanova users" , environments = {Environment.TST1, Environment.PPE})
    void kasanovaConnection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/user-controller/v1/read-users")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_INTEGRATOR)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{}")
                .post()
                .andAssertStatus(200)
                .andAssertFieldValue("ouwmsg", "Success");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1699")
    @TestCase(name = "Get FIPU users" , environments = {Environment.TST1, Environment.PPE})
    void fipuConnection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_ALL_USRS/001")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_INTEGRATOR)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\"INUSER\":\"\"}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("RS_DATA");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1700")
    @TestCase(name = "Get ICBS users", environments = {Environment.TST1, Environment.PPE})
    void icbsConnection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_CBS_USR2/001")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_INTEGRATOR)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\"INCURSOR\":\"1\", \"INROWS\":\"2\"}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("RS_DATA");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1701")
    @TestCase(name = "Get not authorized transactions", environments = {Environment.TST1, Environment.PPE})
    void paeConnection_GWAndTif(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_PAYMENT_AUTH/001")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_UFO)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\"TX_STS\": \"8\",\"BRANCH_ID_IN\": 86001340}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("RS_DATA");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1702")
    @TestCase(name = "RTE health check", environments = {Environment.TST1, Environment.PPE})
    void rteConnection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/rte-management/v1/management/health")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_INTEGRATOR)
                .withHeader("cache-control", "no-cache,no-cache")
                .get()
                .andAssertStatus(200)
                .andAssertPresent("status");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1703")
    @TestCase(name = "C24 health check", environments = {Environment.TST1, Environment.PPE})
    void c24Connection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/management/v1/management/health")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization", TOKEN_INTEGRATOR)
                .withHeader("cache-control", "no-cache,no-cache")
                .get()
                .andAssertPresent("status");
    }

    @Disabled("Not currently maintained")
    @JiraTestCase(id = "PAY-T1704")
    @TestCase(name = "G400", environments = {Environment.TST1, Environment.PPE})
    void G400Connection(Harness harness) {
        harness.withWso2()
                .prepareRequest()
                .withPath("/t/payments.cluster/GET_G4CUST/001")
                .withHeader("Content-Type", "application/json")
                .withHeader("Accept", "application/json")
                .withHeader("Authorization",TOKEN_CBL)
                .withHeader("cache-control", "no-cache,no-cache")
                .withPayload("{\n" +
                        "  \"INBANK\": 1,\n" +
                        "  \"INCIF\": \"string\"\n" +
                        "}")
                .post()
                .andAssertStatus(200)
                .andAssertPresent("OUSTAT");
    }
}
