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

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

    @TestCase(name = "Call API commhub-incoming-messages-event to WSO2", environments = {TST1, PPE})
    public void postCommhubIncomingMessagesEvent(Harness harness) {
        RawRestRequest.Response response = harness.tasks().wso2().restRequest().prepareRequestFromHubToCvm(
                        COMMHUB_INCOMING_MESSAGES_EVENT_PATH, false,
                        "{\n" +
                                "  \"channelMessageId\": 302361894,\n" +
                                "  \"sourceChannelMessageId\": 302361894,\n" +
                                "  \"sourceCommunicationCode\": \"3005\",\n" +
                                "  \"sourceOrganizationalUnit\": \"CRM_RETAIL\",\n" +
                                "  \"messageStatus\": \"SENT\",\n" +
                                "  \"communicationCode\": \"30069\",\n" +
                                "  \"channel\": \"SMS\",\n" +
                                "  \"messageSubject\": \"\",\n" +
                                "  \"messageBody\": \"\",\n" +
                                "  \"senderInfo\": \"MONETA\",\n" +
                                "  \"replyTo\": \"string\",\n" +
                                "  \"attachmentCount\": 0,\n" +
                                "  \"partyId\": \"80013358219\",\n" +
                                "  \"recipientAddress\": \"string\",\n" +
                                "  \"telephoneNumber\": \"420605906050\",\n" +
                                "  \"accountId\": \"string\",\n" +
                                "  \"organizationalUnit\": \"string\",\n" +
                                "  \"messageDataKey\": \"string\",\n" +
                                "  \"messageDataValues\": \"string\",\n" +
                                "  \"createDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"receivedDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"sourceReference\": \"string\",\n" +
                                "  \"sourceCommunicationRecordId\": \"string\",\n" +
                                "  \"sourceMessageId\": 0,\n" +
                                "  \"sourceSendDateTime\": \"" + DateUtils.getFormattedTodayDateTimeForWso2() + "\",\n" +
                                "  \"sourcePersonalStateRegistrationNumber\": \"string\",\n" +
                                "  \"sourceCompanyStateRegistrationNumber\": \"string\",\n" +
                                "  \"sourceTelephoneNumber\": \"string\",\n" +
                                "  \"sourceAddress\": \"string\",\n" +
                                "  \"sourceChannel\": \"string\"\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");
    }
}

