// File generated from our OpenAPI spec by Stainless.

package com.openai.models.beta.assistants

import com.openai.core.JsonValue
import com.openai.models.Metadata
import com.openai.models.beta.threads.messages.ImageFile
import com.openai.models.beta.threads.messages.Message
import com.openai.models.beta.threads.messages.MessageDelta
import com.openai.models.beta.threads.messages.MessageDeltaEvent
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class MessageStreamEventTest {

    @Test
    fun ofThreadMessageCreated() {
        val threadMessageCreated =
            MessageStreamEvent.ThreadMessageCreated.builder()
                .data(
                    Message.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .addAttachment(Message.Attachment.builder().build())
                        .completedAt(0L)
                        .addImageFileContent(ImageFile.builder().fileId("file_id").build())
                        .createdAt(0L)
                        .incompleteAt(0L)
                        .incompleteDetails(
                            Message.IncompleteDetails.builder()
                                .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER)
                                .build()
                        )
                        .metadata(
                            Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .role(Message.Role.USER)
                        .runId("run_id")
                        .status(Message.Status.IN_PROGRESS)
                        .threadId("thread_id")
                        .build()
                )
                .build()

        val messageStreamEvent = MessageStreamEvent.ofThreadMessageCreated(threadMessageCreated)

        assertThat(messageStreamEvent.threadMessageCreated()).contains(threadMessageCreated)
        assertThat(messageStreamEvent.threadMessageInProgress()).isEmpty
        assertThat(messageStreamEvent.threadMessageDelta()).isEmpty
        assertThat(messageStreamEvent.threadMessageCompleted()).isEmpty
        assertThat(messageStreamEvent.threadMessageIncomplete()).isEmpty
    }

    @Test
    fun ofThreadMessageInProgress() {
        val threadMessageInProgress =
            MessageStreamEvent.ThreadMessageInProgress.builder()
                .data(
                    Message.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .addAttachment(Message.Attachment.builder().build())
                        .completedAt(0L)
                        .addImageFileContent(ImageFile.builder().fileId("file_id").build())
                        .createdAt(0L)
                        .incompleteAt(0L)
                        .incompleteDetails(
                            Message.IncompleteDetails.builder()
                                .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER)
                                .build()
                        )
                        .metadata(
                            Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .role(Message.Role.USER)
                        .runId("run_id")
                        .status(Message.Status.IN_PROGRESS)
                        .threadId("thread_id")
                        .build()
                )
                .build()

        val messageStreamEvent =
            MessageStreamEvent.ofThreadMessageInProgress(threadMessageInProgress)

        assertThat(messageStreamEvent.threadMessageCreated()).isEmpty
        assertThat(messageStreamEvent.threadMessageInProgress()).contains(threadMessageInProgress)
        assertThat(messageStreamEvent.threadMessageDelta()).isEmpty
        assertThat(messageStreamEvent.threadMessageCompleted()).isEmpty
        assertThat(messageStreamEvent.threadMessageIncomplete()).isEmpty
    }

    @Test
    fun ofThreadMessageDelta() {
        val threadMessageDelta =
            MessageStreamEvent.ThreadMessageDelta.builder()
                .data(
                    MessageDeltaEvent.builder()
                        .id("id")
                        .delta(MessageDelta.builder().build())
                        .build()
                )
                .build()

        val messageStreamEvent = MessageStreamEvent.ofThreadMessageDelta(threadMessageDelta)

        assertThat(messageStreamEvent.threadMessageCreated()).isEmpty
        assertThat(messageStreamEvent.threadMessageInProgress()).isEmpty
        assertThat(messageStreamEvent.threadMessageDelta()).contains(threadMessageDelta)
        assertThat(messageStreamEvent.threadMessageCompleted()).isEmpty
        assertThat(messageStreamEvent.threadMessageIncomplete()).isEmpty
    }

    @Test
    fun ofThreadMessageCompleted() {
        val threadMessageCompleted =
            MessageStreamEvent.ThreadMessageCompleted.builder()
                .data(
                    Message.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .addAttachment(Message.Attachment.builder().build())
                        .completedAt(0L)
                        .addImageFileContent(ImageFile.builder().fileId("file_id").build())
                        .createdAt(0L)
                        .incompleteAt(0L)
                        .incompleteDetails(
                            Message.IncompleteDetails.builder()
                                .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER)
                                .build()
                        )
                        .metadata(
                            Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .role(Message.Role.USER)
                        .runId("run_id")
                        .status(Message.Status.IN_PROGRESS)
                        .threadId("thread_id")
                        .build()
                )
                .build()

        val messageStreamEvent = MessageStreamEvent.ofThreadMessageCompleted(threadMessageCompleted)

        assertThat(messageStreamEvent.threadMessageCreated()).isEmpty
        assertThat(messageStreamEvent.threadMessageInProgress()).isEmpty
        assertThat(messageStreamEvent.threadMessageDelta()).isEmpty
        assertThat(messageStreamEvent.threadMessageCompleted()).contains(threadMessageCompleted)
        assertThat(messageStreamEvent.threadMessageIncomplete()).isEmpty
    }

    @Test
    fun ofThreadMessageIncomplete() {
        val threadMessageIncomplete =
            MessageStreamEvent.ThreadMessageIncomplete.builder()
                .data(
                    Message.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .addAttachment(Message.Attachment.builder().build())
                        .completedAt(0L)
                        .addImageFileContent(ImageFile.builder().fileId("file_id").build())
                        .createdAt(0L)
                        .incompleteAt(0L)
                        .incompleteDetails(
                            Message.IncompleteDetails.builder()
                                .reason(Message.IncompleteDetails.Reason.CONTENT_FILTER)
                                .build()
                        )
                        .metadata(
                            Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .role(Message.Role.USER)
                        .runId("run_id")
                        .status(Message.Status.IN_PROGRESS)
                        .threadId("thread_id")
                        .build()
                )
                .build()

        val messageStreamEvent =
            MessageStreamEvent.ofThreadMessageIncomplete(threadMessageIncomplete)

        assertThat(messageStreamEvent.threadMessageCreated()).isEmpty
        assertThat(messageStreamEvent.threadMessageInProgress()).isEmpty
        assertThat(messageStreamEvent.threadMessageDelta()).isEmpty
        assertThat(messageStreamEvent.threadMessageCompleted()).isEmpty
        assertThat(messageStreamEvent.threadMessageIncomplete()).contains(threadMessageIncomplete)
    }
}
