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-incoming-messages-trigger to WSO2 and assert response parameters")
public class ApiCommhubIncomingMessagesTrigger {

    public static final String COMMHUB_INCOMING_MESSAGES_TRIGGER_PATH = "cvm.cluster/commhub-incoming-messages-trigger/1.0.0";

    @TestCase(name = "Call API commhub-incoming-messages-trigger to WSO2", environments = {TST1, PPE})
    public void postCommhubIncomingMessagesTrigger(Harness harness) {
        JsonNode outputs = harness.tasks().wso2().restRequest().prepareRequestFromCvm(
                        COMMHUB_INCOMING_MESSAGES_TRIGGER_PATH, false,
                        "{\n" +
                                "  \"correlationId\": \"" + UUID.randomUUID() + "\",\n" +
                                "  \"clientTimeZone\": \"Europe/Prague\",\n" +
                                "  \"version\": 1,\n" +
                                "  \"inputs\": {\n" +
                                "    \"channelMessageId\": 302538558,\n" +
                                "    \"sourceChannelMessageId\": 302538558,\n" +
                                "    \"sourceCommunicationCode\": \"2150RTDM\",\n" +
                                "    \"sourceOrganizationalUnit\": \"CRM_RETAIL\",\n" +
                                "    \"messageStatus\": \"DELIVERED\",\n" +
                                "    \"communicationCode\": \"12345\",\n" +
                                "    \"channel\": \"SMS\",\n" +
                                "    \"messageSubject\": \"\",\n" +
                                "    \"messageBody\": \"Pujcka\",\n" +
                                "    \"senderInfo\": \"MONETA\",\n" +
                                "    \"replyTo\": \"\",\n" +
                                "    \"attachmentCount\": 0,\n" +
                                "    \"partyId\": \"34456666\",\n" +
                                "    \"recipientAddress\": \"\",\n" +
                                "    \"telephoneNumber\": \"734585306\",\n" +
                                "    \"accountId\": \"string\",\n" +
                                "    \"organizationalUnit\": \"CRM_RETAIL\",\n" +
                                "    \"messageDataKey\": \"\",\n" +
                                "    \"messageDataValues\": \"pujcka\",\n" +
                                "    \"createDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "    \"receivedDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "    \"sourceReference\": \"\",\n" +
                                "    \"sourceCommunicationRecordId\": \"\",\n" +
                                "    \"sourceMessageId\": 1094146,\n" +
                                "    \"sourceSendDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "    \"sourcePersonalStateRegistrationNumber\": \"\",\n" +
                                "    \"sourceCompanyStateRegistrationNumber\": \"\",\n" +
                                "    \"sourceTelephoneNumber\": \"\",\n" +
                                "    \"sourceAddress\": \"\",\n" +
                                "    \"sourceChannel\": \"SMS\",\n" +
                                "    \"configurationEventName\": \"commhub-incoming-messages-event\"\n" +
                                "  }\n" +
                                "}")
                .post()
                .andAssertStatus(201)
                .extract("outputs");

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

