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 org.junit.jupiter.api.Assertions;

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 SBA_SAS_RTDM_GetBanners to WSO2 and assert response parameters")
public class ApiSbaSasRtdmGetbanners {

    @TestCase(name = "Call API SBA_SAS_RTDM_GetBanners to WSO2", environments = {TST1, PPE})
    public void postSbaSasRtdmGetbanners(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                "cvm.cluster/SBA_GetBanners/1.0.0", false,
                "{\n" +
                        "    \"version\": 1,\n" +
                        "    \"clientTimeZone\": \"Europe/Prague\",\n" +
                        "    \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                        "    \"inputs\": {\n" +
                        "        \"CIF\": \"" + harness.getConfig("cvm.client.cif") + "\",\n" +
                        "        \"USER_ID\": 1234,\n" +
                        "        \"CHANNEL_ID\": \"SBA\"\n" +
                        "    }\n" +
                        "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

        JsonNode count = outputs.findValue("COUNT");
        Assertions.assertTrue(count != null && count.asInt() >= 0, "Not found COUNT with value >= 0");
    }
}