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

    public static final String COMMHUB_NOTIFICATION_TRIGGER_PATH = "cvm.cluster/commhub-notification-trigger/1.0.0";

    @TestCase(name = "Call API commhub-notification-trigger to WSO2", environments = {TST1, PPE})
    public void postCommhubNotificationTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                        COMMHUB_NOTIFICATION_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"version\": 1,\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"inputs\": {\n" +
                                "    \"configurationEventName\": \"commHubEvent/cvm\",\n" +
                                "    \"eventId\": 302538606,\n" +
                                "    \"channelMessageId\": 302538558,\n" +
                                "    \"messageId\": 302538558,\n" +
                                "    \"reference\": null,\n" +
                                "    \"type\": \"DELIVER\",\n" +
                                "    \"value\": null,\n" +
                                "    \"messageState\": \"DELIVERED\",\n" +
                                "    \"eventDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "    \"channel\": \"EMAIL\",\n" +
                                "    \"partyId\": null,\n" +
                                "    \"communicationRecordId\": null,\n" +
                                "    \"communicationCode\": \"2150RTDM\",\n" +
                                "    \"costCenter\": \"3005\",\n" +
                                "    \"organizationalUnit\": \"CRM_KOMERCNI\",\n" +
                                "    \"senderInfo\": \"stavebko@moneta.cz\",\n" +
                                "    \"emailAddress\": \"212625901@moneta.cz\",\n" +
                                "    \"telephoneNumber\": null,\n" +
                                "    \"deviceId\": null,\n" +
                                "    \"eventDetailsValueType\": \"\"\n" +
                                "  }\n" +
                                "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

