// File generated from our OpenAPI spec by Stainless.

package com.openai.models

import com.openai.core.JsonValue
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class RunTest {

    @Test
    fun createRun() {
        val run =
            Run.builder()
                .id("id")
                .assistantId("assistant_id")
                .cancelledAt(0L)
                .completedAt(0L)
                .createdAt(0L)
                .expiresAt(0L)
                .failedAt(0L)
                .incompleteDetails(
                    Run.IncompleteDetails.builder()
                        .reason(Run.IncompleteDetails.Reason.MAX_COMPLETION_TOKENS)
                        .build()
                )
                .instructions("instructions")
                .lastError(
                    Run.LastError.builder()
                        .code(Run.LastError.Code.SERVER_ERROR)
                        .message("message")
                        .build()
                )
                .maxCompletionTokens(256L)
                .maxPromptTokens(256L)
                .metadata(JsonValue.from(mapOf<String, Any>()))
                .model("model")
                .object_(Run.Object.THREAD_RUN)
                .parallelToolCalls(true)
                .requiredAction(
                    Run.RequiredAction.builder()
                        .submitToolOutputs(
                            Run.RequiredAction.SubmitToolOutputs.builder()
                                .toolCalls(
                                    listOf(
                                        RequiredActionFunctionToolCall.builder()
                                            .id("id")
                                            .function(
                                                RequiredActionFunctionToolCall.Function.builder()
                                                    .arguments("arguments")
                                                    .name("name")
                                                    .build()
                                            )
                                            .type(RequiredActionFunctionToolCall.Type.FUNCTION)
                                            .build()
                                    )
                                )
                                .build()
                        )
                        .type(Run.RequiredAction.Type.SUBMIT_TOOL_OUTPUTS)
                        .build()
                )
                .responseFormat(
                    AssistantResponseFormatOption.ofBehavior(
                        AssistantResponseFormatOption.Behavior.AUTO
                    )
                )
                .startedAt(0L)
                .status(RunStatus.QUEUED)
                .threadId("thread_id")
                .toolChoice(
                    AssistantToolChoiceOption.ofBehavior(AssistantToolChoiceOption.Behavior.NONE)
                )
                .tools(
                    listOf(
                        AssistantTool.ofCodeInterpreterTool(
                            CodeInterpreterTool.builder()
                                .type(CodeInterpreterTool.Type.CODE_INTERPRETER)
                                .build()
                        )
                    )
                )
                .truncationStrategy(
                    Run.TruncationStrategy.builder()
                        .type(Run.TruncationStrategy.Type.AUTO)
                        .lastMessages(1L)
                        .build()
                )
                .usage(
                    Run.Usage.builder()
                        .completionTokens(0L)
                        .promptTokens(0L)
                        .totalTokens(0L)
                        .build()
                )
                .temperature(0.0)
                .topP(0.0)
                .build()
        assertThat(run).isNotNull
        assertThat(run.id()).isEqualTo("id")
        assertThat(run.assistantId()).isEqualTo("assistant_id")
        assertThat(run.cancelledAt()).contains(0L)
        assertThat(run.completedAt()).contains(0L)
        assertThat(run.createdAt()).isEqualTo(0L)
        assertThat(run.expiresAt()).contains(0L)
        assertThat(run.failedAt()).contains(0L)
        assertThat(run.incompleteDetails())
            .contains(
                Run.IncompleteDetails.builder()
                    .reason(Run.IncompleteDetails.Reason.MAX_COMPLETION_TOKENS)
                    .build()
            )
        assertThat(run.instructions()).isEqualTo("instructions")
        assertThat(run.lastError())
            .contains(
                Run.LastError.builder()
                    .code(Run.LastError.Code.SERVER_ERROR)
                    .message("message")
                    .build()
            )
        assertThat(run.maxCompletionTokens()).contains(256L)
        assertThat(run.maxPromptTokens()).contains(256L)
        assertThat(run._metadata()).isEqualTo(JsonValue.from(mapOf<String, Any>()))
        assertThat(run.model()).isEqualTo("model")
        assertThat(run.object_()).isEqualTo(Run.Object.THREAD_RUN)
        assertThat(run.parallelToolCalls()).isEqualTo(true)
        assertThat(run.requiredAction())
            .contains(
                Run.RequiredAction.builder()
                    .submitToolOutputs(
                        Run.RequiredAction.SubmitToolOutputs.builder()
                            .toolCalls(
                                listOf(
                                    RequiredActionFunctionToolCall.builder()
                                        .id("id")
                                        .function(
                                            RequiredActionFunctionToolCall.Function.builder()
                                                .arguments("arguments")
                                                .name("name")
                                                .build()
                                        )
                                        .type(RequiredActionFunctionToolCall.Type.FUNCTION)
                                        .build()
                                )
                            )
                            .build()
                    )
                    .type(Run.RequiredAction.Type.SUBMIT_TOOL_OUTPUTS)
                    .build()
            )
        assertThat(run.responseFormat())
            .contains(
                AssistantResponseFormatOption.ofBehavior(
                    AssistantResponseFormatOption.Behavior.AUTO
                )
            )
        assertThat(run.startedAt()).contains(0L)
        assertThat(run.status()).isEqualTo(RunStatus.QUEUED)
        assertThat(run.threadId()).isEqualTo("thread_id")
        assertThat(run.toolChoice())
            .contains(AssistantToolChoiceOption.ofBehavior(AssistantToolChoiceOption.Behavior.NONE))
        assertThat(run.tools())
            .containsExactly(
                AssistantTool.ofCodeInterpreterTool(
                    CodeInterpreterTool.builder()
                        .type(CodeInterpreterTool.Type.CODE_INTERPRETER)
                        .build()
                )
            )
        assertThat(run.truncationStrategy())
            .contains(
                Run.TruncationStrategy.builder()
                    .type(Run.TruncationStrategy.Type.AUTO)
                    .lastMessages(1L)
                    .build()
            )
        assertThat(run.usage())
            .contains(
                Run.Usage.builder().completionTokens(0L).promptTokens(0L).totalTokens(0L).build()
            )
        assertThat(run.temperature()).contains(0.0)
        assertThat(run.topP()).contains(0.0)
    }
}
