// File generated from our OpenAPI spec by Stainless.

package com.openai.models.beta.assistants

import com.openai.core.JsonValue
import com.openai.models.beta.threads.AssistantToolChoiceOption
import com.openai.models.beta.threads.runs.RequiredActionFunctionToolCall
import com.openai.models.beta.threads.runs.Run
import com.openai.models.beta.threads.runs.RunStatus
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class RunStreamEventTest {

    @Test
    fun ofThreadRunCreated() {
        val threadRunCreated =
            RunStreamEvent.ThreadRunCreated.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunCreated(threadRunCreated)

        assertThat(runStreamEvent.threadRunCreated()).contains(threadRunCreated)
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunQueued() {
        val threadRunQueued =
            RunStreamEvent.ThreadRunQueued.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunQueued(threadRunQueued)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).contains(threadRunQueued)
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunInProgress() {
        val threadRunInProgress =
            RunStreamEvent.ThreadRunInProgress.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunInProgress(threadRunInProgress)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).contains(threadRunInProgress)
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunRequiresAction() {
        val threadRunRequiresAction =
            RunStreamEvent.ThreadRunRequiresAction.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunRequiresAction(threadRunRequiresAction)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).contains(threadRunRequiresAction)
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunCompleted() {
        val threadRunCompleted =
            RunStreamEvent.ThreadRunCompleted.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunCompleted(threadRunCompleted)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).contains(threadRunCompleted)
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunIncomplete() {
        val threadRunIncomplete =
            RunStreamEvent.ThreadRunIncomplete.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunIncomplete(threadRunIncomplete)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).contains(threadRunIncomplete)
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunFailed() {
        val threadRunFailed =
            RunStreamEvent.ThreadRunFailed.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunFailed(threadRunFailed)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).contains(threadRunFailed)
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunCancelling() {
        val threadRunCancelling =
            RunStreamEvent.ThreadRunCancelling.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunCancelling(threadRunCancelling)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).contains(threadRunCancelling)
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunCancelled() {
        val threadRunCancelled =
            RunStreamEvent.ThreadRunCancelled.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunCancelled(threadRunCancelled)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).contains(threadRunCancelled)
        assertThat(runStreamEvent.threadRunExpired()).isEmpty
    }

    @Test
    fun ofThreadRunExpired() {
        val threadRunExpired =
            RunStreamEvent.ThreadRunExpired.builder()
                .data(
                    Run.builder()
                        .id("id")
                        .assistantId("assistant_id")
                        .cancelledAt(0L)
                        .completedAt(0L)
                        .createdAt(0L)
                        .expiresAt(0L)
                        .failedAt(0L)
                        .incompleteDetails(Run.IncompleteDetails.builder().build())
                        .instructions("instructions")
                        .lastError(
                            Run.LastError.builder()
                                .code(Run.LastError.Code.SERVER_ERROR)
                                .message("message")
                                .build()
                        )
                        .maxCompletionTokens(256L)
                        .maxPromptTokens(256L)
                        .metadata(
                            Run.Metadata.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .model("model")
                        .parallelToolCalls(true)
                        .requiredAction(
                            Run.RequiredAction.builder()
                                .submitToolOutputs(
                                    Run.RequiredAction.SubmitToolOutputs.builder()
                                        .addToolCall(
                                            RequiredActionFunctionToolCall.builder()
                                                .id("id")
                                                .function(
                                                    RequiredActionFunctionToolCall.Function
                                                        .builder()
                                                        .arguments("arguments")
                                                        .name("name")
                                                        .build()
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .build()
                        )
                        .responseFormatJsonValue()
                        .startedAt(0L)
                        .status(RunStatus.QUEUED)
                        .threadId("thread_id")
                        .toolChoice(AssistantToolChoiceOption.Auto.NONE)
                        .addTool(CodeInterpreterTool.builder().build())
                        .truncationStrategy(
                            Run.TruncationStrategy.builder()
                                .type(Run.TruncationStrategy.Type.AUTO)
                                .build()
                        )
                        .usage(
                            Run.Usage.builder()
                                .completionTokens(0L)
                                .promptTokens(0L)
                                .totalTokens(0L)
                                .build()
                        )
                        .build()
                )
                .build()

        val runStreamEvent = RunStreamEvent.ofThreadRunExpired(threadRunExpired)

        assertThat(runStreamEvent.threadRunCreated()).isEmpty
        assertThat(runStreamEvent.threadRunQueued()).isEmpty
        assertThat(runStreamEvent.threadRunInProgress()).isEmpty
        assertThat(runStreamEvent.threadRunRequiresAction()).isEmpty
        assertThat(runStreamEvent.threadRunCompleted()).isEmpty
        assertThat(runStreamEvent.threadRunIncomplete()).isEmpty
        assertThat(runStreamEvent.threadRunFailed()).isEmpty
        assertThat(runStreamEvent.threadRunCancelling()).isEmpty
        assertThat(runStreamEvent.threadRunCancelled()).isEmpty
        assertThat(runStreamEvent.threadRunExpired()).contains(threadRunExpired)
    }
}
