package cz.moneta.test.regression.cvm.api.cvm;

import com.fasterxml.jackson.databind.JsonNode;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.rest.RawRestRequest;

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 commhub-notification-event to WSO2 and assert response parameters")
public class ApiCommhubNotificationEvent {

    public static final String COMMHUB_NOTIFICATION_EVENT_PATH = "cvm.cluster/commhub-notification-event/1.0.0";

    @TestCase(name = "Call API commhub-notification-event to WSO2", environments = {TST1, PPE})
    public void postCommhubNotificationEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromOptimusHubToCvm(
                        COMMHUB_NOTIFICATION_EVENT_PATH, false,
                        "{\n" +
                                "  \"eventId\": 302538606,\n" +
                                "  \"channelMessageId\": 302538558,\n" +
                                "  \"messageId\": 302538558,\n" +
                                "  \"type\": \"SEND\",\n" +
                                "  \"messageState\": \"SENT\",\n" +
                                "  \"eventDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"channel\": \"SMS\",\n" +
                                "  \"partyId\": 850980,\n" +
                                "  \"communicationRecordId\": null,\n" +
                                "  \"communicationCode\": \"2150RTDM\",\n" +
                                "  \"costCenter\": \"A000\",\n" +
                                "  \"organizationalUnit\": \"CRM_RETAIL\",\n" +
                                "  \"senderInfo\": \"420736343000\",\n" +
                                "  \"telephoneNumber\": \"420776132887\",\n" +
                                "  \"eventDetailsValueType\": \"\"\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");
    }
}

