// File generated from our OpenAPI spec by Stainless.

package com.openai.models.responses

import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.JsonValue
import com.openai.core.jsonMapper
import com.openai.errors.OpenAIInvalidDataException
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.EnumSource

internal class ResponseOutputItemTest {

    @Test
    fun ofMessage() {
        val message =
            ResponseOutputMessage.builder()
                .id("id")
                .addContent(
                    ResponseOutputText.builder()
                        .addAnnotation(
                            ResponseOutputText.Annotation.FileCitation.builder()
                                .fileId("file_id")
                                .filename("filename")
                                .index(0L)
                                .build()
                        )
                        .text("text")
                        .addLogprob(
                            ResponseOutputText.Logprob.builder()
                                .token("token")
                                .addByte(0L)
                                .logprob(0.0)
                                .addTopLogprob(
                                    ResponseOutputText.Logprob.TopLogprob.builder()
                                        .token("token")
                                        .addByte(0L)
                                        .logprob(0.0)
                                        .build()
                                )
                                .build()
                        )
                        .build()
                )
                .status(ResponseOutputMessage.Status.IN_PROGRESS)
                .phase(ResponseOutputMessage.Phase.COMMENTARY)
                .build()

        val responseOutputItem = ResponseOutputItem.ofMessage(message)

        assertThat(responseOutputItem.message()).contains(message)
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofMessageRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofMessage(
                ResponseOutputMessage.builder()
                    .id("id")
                    .addContent(
                        ResponseOutputText.builder()
                            .addAnnotation(
                                ResponseOutputText.Annotation.FileCitation.builder()
                                    .fileId("file_id")
                                    .filename("filename")
                                    .index(0L)
                                    .build()
                            )
                            .text("text")
                            .addLogprob(
                                ResponseOutputText.Logprob.builder()
                                    .token("token")
                                    .addByte(0L)
                                    .logprob(0.0)
                                    .addTopLogprob(
                                        ResponseOutputText.Logprob.TopLogprob.builder()
                                            .token("token")
                                            .addByte(0L)
                                            .logprob(0.0)
                                            .build()
                                    )
                                    .build()
                            )
                            .build()
                    )
                    .status(ResponseOutputMessage.Status.IN_PROGRESS)
                    .phase(ResponseOutputMessage.Phase.COMMENTARY)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofFileSearchCall() {
        val fileSearchCall =
            ResponseFileSearchToolCall.builder()
                .id("id")
                .addQuery("string")
                .status(ResponseFileSearchToolCall.Status.IN_PROGRESS)
                .addResult(
                    ResponseFileSearchToolCall.Result.builder()
                        .attributes(
                            ResponseFileSearchToolCall.Result.Attributes.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .fileId("file_id")
                        .filename("filename")
                        .score(0.0f)
                        .text("text")
                        .build()
                )
                .build()

        val responseOutputItem = ResponseOutputItem.ofFileSearchCall(fileSearchCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).contains(fileSearchCall)
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofFileSearchCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofFileSearchCall(
                ResponseFileSearchToolCall.builder()
                    .id("id")
                    .addQuery("string")
                    .status(ResponseFileSearchToolCall.Status.IN_PROGRESS)
                    .addResult(
                        ResponseFileSearchToolCall.Result.builder()
                            .attributes(
                                ResponseFileSearchToolCall.Result.Attributes.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("string"))
                                    .build()
                            )
                            .fileId("file_id")
                            .filename("filename")
                            .score(0.0f)
                            .text("text")
                            .build()
                    )
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofFunctionCall() {
        val functionCall =
            ResponseFunctionToolCall.builder()
                .arguments("arguments")
                .callId("call_id")
                .name("name")
                .id("id")
                .namespace("namespace")
                .status(ResponseFunctionToolCall.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofFunctionCall(functionCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).contains(functionCall)
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofFunctionCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofFunctionCall(
                ResponseFunctionToolCall.builder()
                    .arguments("arguments")
                    .callId("call_id")
                    .name("name")
                    .id("id")
                    .namespace("namespace")
                    .status(ResponseFunctionToolCall.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofFunctionCallOutput() {
        val functionCallOutput =
            ResponseFunctionToolCallOutputItem.builder()
                .id("id")
                .callId("call_id")
                .output("string")
                .status(ResponseFunctionToolCallOutputItem.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofFunctionCallOutput(functionCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).contains(functionCallOutput)
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofFunctionCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofFunctionCallOutput(
                ResponseFunctionToolCallOutputItem.builder()
                    .id("id")
                    .callId("call_id")
                    .output("string")
                    .status(ResponseFunctionToolCallOutputItem.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofWebSearchCall() {
        val webSearchCall =
            ResponseFunctionWebSearch.builder()
                .id("id")
                .action(
                    ResponseFunctionWebSearch.Action.Search.builder()
                        .query("query")
                        .addQuery("string")
                        .addSource(
                            ResponseFunctionWebSearch.Action.Search.Source.builder()
                                .url("https://example.com")
                                .build()
                        )
                        .build()
                )
                .status(ResponseFunctionWebSearch.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofWebSearchCall(webSearchCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).contains(webSearchCall)
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofWebSearchCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofWebSearchCall(
                ResponseFunctionWebSearch.builder()
                    .id("id")
                    .action(
                        ResponseFunctionWebSearch.Action.Search.builder()
                            .query("query")
                            .addQuery("string")
                            .addSource(
                                ResponseFunctionWebSearch.Action.Search.Source.builder()
                                    .url("https://example.com")
                                    .build()
                            )
                            .build()
                    )
                    .status(ResponseFunctionWebSearch.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofComputerCall() {
        val computerCall =
            ResponseComputerToolCall.builder()
                .id("id")
                .callId("call_id")
                .addPendingSafetyCheck(
                    ResponseComputerToolCall.PendingSafetyCheck.builder()
                        .id("id")
                        .code("code")
                        .message("message")
                        .build()
                )
                .status(ResponseComputerToolCall.Status.IN_PROGRESS)
                .type(ResponseComputerToolCall.Type.COMPUTER_CALL)
                .action(
                    ResponseComputerToolCall.Action.Click.builder()
                        .button(ResponseComputerToolCall.Action.Click.Button.LEFT)
                        .x(0L)
                        .y(0L)
                        .addKey("string")
                        .build()
                )
                .addAction(
                    ComputerAction.Click.builder()
                        .button(ComputerAction.Click.Button.LEFT)
                        .x(0L)
                        .y(0L)
                        .addKey("string")
                        .build()
                )
                .build()

        val responseOutputItem = ResponseOutputItem.ofComputerCall(computerCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).contains(computerCall)
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofComputerCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofComputerCall(
                ResponseComputerToolCall.builder()
                    .id("id")
                    .callId("call_id")
                    .addPendingSafetyCheck(
                        ResponseComputerToolCall.PendingSafetyCheck.builder()
                            .id("id")
                            .code("code")
                            .message("message")
                            .build()
                    )
                    .status(ResponseComputerToolCall.Status.IN_PROGRESS)
                    .type(ResponseComputerToolCall.Type.COMPUTER_CALL)
                    .action(
                        ResponseComputerToolCall.Action.Click.builder()
                            .button(ResponseComputerToolCall.Action.Click.Button.LEFT)
                            .x(0L)
                            .y(0L)
                            .addKey("string")
                            .build()
                    )
                    .addAction(
                        ComputerAction.Click.builder()
                            .button(ComputerAction.Click.Button.LEFT)
                            .x(0L)
                            .y(0L)
                            .addKey("string")
                            .build()
                    )
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofComputerCallOutput() {
        val computerCallOutput =
            ResponseComputerToolCallOutputItem.builder()
                .id("id")
                .callId("call_id")
                .output(
                    ResponseComputerToolCallOutputScreenshot.builder()
                        .fileId("file_id")
                        .imageUrl("https://example.com")
                        .build()
                )
                .status(ResponseComputerToolCallOutputItem.Status.COMPLETED)
                .addAcknowledgedSafetyCheck(
                    ResponseComputerToolCallOutputItem.AcknowledgedSafetyCheck.builder()
                        .id("id")
                        .code("code")
                        .message("message")
                        .build()
                )
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofComputerCallOutput(computerCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).contains(computerCallOutput)
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofComputerCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofComputerCallOutput(
                ResponseComputerToolCallOutputItem.builder()
                    .id("id")
                    .callId("call_id")
                    .output(
                        ResponseComputerToolCallOutputScreenshot.builder()
                            .fileId("file_id")
                            .imageUrl("https://example.com")
                            .build()
                    )
                    .status(ResponseComputerToolCallOutputItem.Status.COMPLETED)
                    .addAcknowledgedSafetyCheck(
                        ResponseComputerToolCallOutputItem.AcknowledgedSafetyCheck.builder()
                            .id("id")
                            .code("code")
                            .message("message")
                            .build()
                    )
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofReasoning() {
        val reasoning =
            ResponseReasoningItem.builder()
                .id("id")
                .addSummary(ResponseReasoningItem.Summary.builder().text("text").build())
                .addContent(ResponseReasoningItem.Content.builder().text("text").build())
                .encryptedContent("encrypted_content")
                .status(ResponseReasoningItem.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofReasoning(reasoning)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).contains(reasoning)
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofReasoningRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofReasoning(
                ResponseReasoningItem.builder()
                    .id("id")
                    .addSummary(ResponseReasoningItem.Summary.builder().text("text").build())
                    .addContent(ResponseReasoningItem.Content.builder().text("text").build())
                    .encryptedContent("encrypted_content")
                    .status(ResponseReasoningItem.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofToolSearchCall() {
        val toolSearchCall =
            ResponseToolSearchCall.builder()
                .id("id")
                .arguments(JsonValue.from(mapOf<String, Any>()))
                .callId("call_id")
                .execution(ResponseToolSearchCall.Execution.SERVER)
                .status(ResponseToolSearchCall.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofToolSearchCall(toolSearchCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).contains(toolSearchCall)
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofToolSearchCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofToolSearchCall(
                ResponseToolSearchCall.builder()
                    .id("id")
                    .arguments(JsonValue.from(mapOf<String, Any>()))
                    .callId("call_id")
                    .execution(ResponseToolSearchCall.Execution.SERVER)
                    .status(ResponseToolSearchCall.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofToolSearchOutput() {
        val toolSearchOutput =
            ResponseToolSearchOutputItem.builder()
                .id("id")
                .callId("call_id")
                .execution(ResponseToolSearchOutputItem.Execution.SERVER)
                .status(ResponseToolSearchOutputItem.Status.IN_PROGRESS)
                .addTool(
                    FunctionTool.builder()
                        .name("name")
                        .parameters(
                            FunctionTool.Parameters.builder()
                                .putAdditionalProperty("foo", JsonValue.from("bar"))
                                .build()
                        )
                        .strict(true)
                        .deferLoading(true)
                        .description("description")
                        .build()
                )
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofToolSearchOutput(toolSearchOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).contains(toolSearchOutput)
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofToolSearchOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofToolSearchOutput(
                ResponseToolSearchOutputItem.builder()
                    .id("id")
                    .callId("call_id")
                    .execution(ResponseToolSearchOutputItem.Execution.SERVER)
                    .status(ResponseToolSearchOutputItem.Status.IN_PROGRESS)
                    .addTool(
                        FunctionTool.builder()
                            .name("name")
                            .parameters(
                                FunctionTool.Parameters.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("bar"))
                                    .build()
                            )
                            .strict(true)
                            .deferLoading(true)
                            .description("description")
                            .build()
                    )
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofCompaction() {
        val compaction =
            ResponseCompactionItem.builder()
                .id("id")
                .encryptedContent("encrypted_content")
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofCompaction(compaction)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).contains(compaction)
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofCompactionRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofCompaction(
                ResponseCompactionItem.builder()
                    .id("id")
                    .encryptedContent("encrypted_content")
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofImageGenerationCall() {
        val imageGenerationCall =
            ResponseOutputItem.ImageGenerationCall.builder()
                .id("id")
                .result("result")
                .status(ResponseOutputItem.ImageGenerationCall.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofImageGenerationCall(imageGenerationCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).contains(imageGenerationCall)
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofImageGenerationCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofImageGenerationCall(
                ResponseOutputItem.ImageGenerationCall.builder()
                    .id("id")
                    .result("result")
                    .status(ResponseOutputItem.ImageGenerationCall.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofCodeInterpreterCall() {
        val codeInterpreterCall =
            ResponseCodeInterpreterToolCall.builder()
                .id("id")
                .code("code")
                .containerId("container_id")
                .addLogsOutput("logs")
                .status(ResponseCodeInterpreterToolCall.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofCodeInterpreterCall(codeInterpreterCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).contains(codeInterpreterCall)
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofCodeInterpreterCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofCodeInterpreterCall(
                ResponseCodeInterpreterToolCall.builder()
                    .id("id")
                    .code("code")
                    .containerId("container_id")
                    .addLogsOutput("logs")
                    .status(ResponseCodeInterpreterToolCall.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofLocalShellCall() {
        val localShellCall =
            ResponseOutputItem.LocalShellCall.builder()
                .id("id")
                .action(
                    ResponseOutputItem.LocalShellCall.Action.builder()
                        .addCommand("string")
                        .env(
                            ResponseOutputItem.LocalShellCall.Action.Env.builder()
                                .putAdditionalProperty("foo", JsonValue.from("string"))
                                .build()
                        )
                        .timeoutMs(0L)
                        .user("user")
                        .workingDirectory("working_directory")
                        .build()
                )
                .callId("call_id")
                .status(ResponseOutputItem.LocalShellCall.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofLocalShellCall(localShellCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).contains(localShellCall)
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofLocalShellCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofLocalShellCall(
                ResponseOutputItem.LocalShellCall.builder()
                    .id("id")
                    .action(
                        ResponseOutputItem.LocalShellCall.Action.builder()
                            .addCommand("string")
                            .env(
                                ResponseOutputItem.LocalShellCall.Action.Env.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("string"))
                                    .build()
                            )
                            .timeoutMs(0L)
                            .user("user")
                            .workingDirectory("working_directory")
                            .build()
                    )
                    .callId("call_id")
                    .status(ResponseOutputItem.LocalShellCall.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofLocalShellCallOutput() {
        val localShellCallOutput =
            ResponseOutputItem.LocalShellCallOutput.builder()
                .id("id")
                .output("output")
                .status(ResponseOutputItem.LocalShellCallOutput.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofLocalShellCallOutput(localShellCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).contains(localShellCallOutput)
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofLocalShellCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofLocalShellCallOutput(
                ResponseOutputItem.LocalShellCallOutput.builder()
                    .id("id")
                    .output("output")
                    .status(ResponseOutputItem.LocalShellCallOutput.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofShellCall() {
        val shellCall =
            ResponseFunctionShellToolCall.builder()
                .id("id")
                .action(
                    ResponseFunctionShellToolCall.Action.builder()
                        .addCommand("string")
                        .maxOutputLength(0L)
                        .timeoutMs(0L)
                        .build()
                )
                .callId("call_id")
                .environment(ResponseLocalEnvironment.builder().build())
                .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofShellCall(shellCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).contains(shellCall)
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofShellCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofShellCall(
                ResponseFunctionShellToolCall.builder()
                    .id("id")
                    .action(
                        ResponseFunctionShellToolCall.Action.builder()
                            .addCommand("string")
                            .maxOutputLength(0L)
                            .timeoutMs(0L)
                            .build()
                    )
                    .callId("call_id")
                    .environment(ResponseLocalEnvironment.builder().build())
                    .status(ResponseFunctionShellToolCall.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofShellCallOutput() {
        val shellCallOutput =
            ResponseFunctionShellToolCallOutput.builder()
                .id("id")
                .callId("call_id")
                .maxOutputLength(0L)
                .addOutput(
                    ResponseFunctionShellToolCallOutput.Output.builder()
                        .outcomeTimeout()
                        .stderr("stderr")
                        .stdout("stdout")
                        .createdBy("created_by")
                        .build()
                )
                .status(ResponseFunctionShellToolCallOutput.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofShellCallOutput(shellCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).contains(shellCallOutput)
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofShellCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofShellCallOutput(
                ResponseFunctionShellToolCallOutput.builder()
                    .id("id")
                    .callId("call_id")
                    .maxOutputLength(0L)
                    .addOutput(
                        ResponseFunctionShellToolCallOutput.Output.builder()
                            .outcomeTimeout()
                            .stderr("stderr")
                            .stdout("stdout")
                            .createdBy("created_by")
                            .build()
                    )
                    .status(ResponseFunctionShellToolCallOutput.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofApplyPatchCall() {
        val applyPatchCall =
            ResponseApplyPatchToolCall.builder()
                .id("id")
                .callId("call_id")
                .operation(
                    ResponseApplyPatchToolCall.Operation.CreateFile.builder()
                        .diff("diff")
                        .path("path")
                        .build()
                )
                .status(ResponseApplyPatchToolCall.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofApplyPatchCall(applyPatchCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).contains(applyPatchCall)
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofApplyPatchCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofApplyPatchCall(
                ResponseApplyPatchToolCall.builder()
                    .id("id")
                    .callId("call_id")
                    .operation(
                        ResponseApplyPatchToolCall.Operation.CreateFile.builder()
                            .diff("diff")
                            .path("path")
                            .build()
                    )
                    .status(ResponseApplyPatchToolCall.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofApplyPatchCallOutput() {
        val applyPatchCallOutput =
            ResponseApplyPatchToolCallOutput.builder()
                .id("id")
                .callId("call_id")
                .status(ResponseApplyPatchToolCallOutput.Status.COMPLETED)
                .createdBy("created_by")
                .output("output")
                .build()

        val responseOutputItem = ResponseOutputItem.ofApplyPatchCallOutput(applyPatchCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).contains(applyPatchCallOutput)
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofApplyPatchCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofApplyPatchCallOutput(
                ResponseApplyPatchToolCallOutput.builder()
                    .id("id")
                    .callId("call_id")
                    .status(ResponseApplyPatchToolCallOutput.Status.COMPLETED)
                    .createdBy("created_by")
                    .output("output")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofMcpCall() {
        val mcpCall =
            ResponseOutputItem.McpCall.builder()
                .id("id")
                .arguments("arguments")
                .name("name")
                .serverLabel("server_label")
                .approvalRequestId("approval_request_id")
                .error("error")
                .output("output")
                .status(ResponseOutputItem.McpCall.Status.IN_PROGRESS)
                .build()

        val responseOutputItem = ResponseOutputItem.ofMcpCall(mcpCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).contains(mcpCall)
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofMcpCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofMcpCall(
                ResponseOutputItem.McpCall.builder()
                    .id("id")
                    .arguments("arguments")
                    .name("name")
                    .serverLabel("server_label")
                    .approvalRequestId("approval_request_id")
                    .error("error")
                    .output("output")
                    .status(ResponseOutputItem.McpCall.Status.IN_PROGRESS)
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofMcpListTools() {
        val mcpListTools =
            ResponseOutputItem.McpListTools.builder()
                .id("id")
                .serverLabel("server_label")
                .addTool(
                    ResponseOutputItem.McpListTools.Tool.builder()
                        .inputSchema(JsonValue.from(mapOf<String, Any>()))
                        .name("name")
                        .annotations(JsonValue.from(mapOf<String, Any>()))
                        .description("description")
                        .build()
                )
                .error("error")
                .build()

        val responseOutputItem = ResponseOutputItem.ofMcpListTools(mcpListTools)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).contains(mcpListTools)
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofMcpListToolsRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofMcpListTools(
                ResponseOutputItem.McpListTools.builder()
                    .id("id")
                    .serverLabel("server_label")
                    .addTool(
                        ResponseOutputItem.McpListTools.Tool.builder()
                            .inputSchema(JsonValue.from(mapOf<String, Any>()))
                            .name("name")
                            .annotations(JsonValue.from(mapOf<String, Any>()))
                            .description("description")
                            .build()
                    )
                    .error("error")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofMcpApprovalRequest() {
        val mcpApprovalRequest =
            ResponseOutputItem.McpApprovalRequest.builder()
                .id("id")
                .arguments("arguments")
                .name("name")
                .serverLabel("server_label")
                .build()

        val responseOutputItem = ResponseOutputItem.ofMcpApprovalRequest(mcpApprovalRequest)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).contains(mcpApprovalRequest)
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofMcpApprovalRequestRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofMcpApprovalRequest(
                ResponseOutputItem.McpApprovalRequest.builder()
                    .id("id")
                    .arguments("arguments")
                    .name("name")
                    .serverLabel("server_label")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofMcpApprovalResponse() {
        val mcpApprovalResponse =
            ResponseOutputItem.McpApprovalResponse.builder()
                .id("id")
                .approvalRequestId("approval_request_id")
                .approve(true)
                .reason("reason")
                .build()

        val responseOutputItem = ResponseOutputItem.ofMcpApprovalResponse(mcpApprovalResponse)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).contains(mcpApprovalResponse)
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofMcpApprovalResponseRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofMcpApprovalResponse(
                ResponseOutputItem.McpApprovalResponse.builder()
                    .id("id")
                    .approvalRequestId("approval_request_id")
                    .approve(true)
                    .reason("reason")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofCustomToolCall() {
        val customToolCall =
            ResponseCustomToolCall.builder()
                .callId("call_id")
                .input("input")
                .name("name")
                .id("id")
                .namespace("namespace")
                .build()

        val responseOutputItem = ResponseOutputItem.ofCustomToolCall(customToolCall)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).contains(customToolCall)
        assertThat(responseOutputItem.customToolCallOutput()).isEmpty
    }

    @Test
    fun ofCustomToolCallRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofCustomToolCall(
                ResponseCustomToolCall.builder()
                    .callId("call_id")
                    .input("input")
                    .name("name")
                    .id("id")
                    .namespace("namespace")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    @Test
    fun ofCustomToolCallOutput() {
        val customToolCallOutput =
            ResponseCustomToolCallOutputItem.builder()
                .callId("call_id")
                .output("string")
                .id("id")
                .status(ResponseCustomToolCallOutputItem.Status.IN_PROGRESS)
                .createdBy("created_by")
                .build()

        val responseOutputItem = ResponseOutputItem.ofCustomToolCallOutput(customToolCallOutput)

        assertThat(responseOutputItem.message()).isEmpty
        assertThat(responseOutputItem.fileSearchCall()).isEmpty
        assertThat(responseOutputItem.functionCall()).isEmpty
        assertThat(responseOutputItem.functionCallOutput()).isEmpty
        assertThat(responseOutputItem.webSearchCall()).isEmpty
        assertThat(responseOutputItem.computerCall()).isEmpty
        assertThat(responseOutputItem.computerCallOutput()).isEmpty
        assertThat(responseOutputItem.reasoning()).isEmpty
        assertThat(responseOutputItem.toolSearchCall()).isEmpty
        assertThat(responseOutputItem.toolSearchOutput()).isEmpty
        assertThat(responseOutputItem.compaction()).isEmpty
        assertThat(responseOutputItem.imageGenerationCall()).isEmpty
        assertThat(responseOutputItem.codeInterpreterCall()).isEmpty
        assertThat(responseOutputItem.localShellCall()).isEmpty
        assertThat(responseOutputItem.localShellCallOutput()).isEmpty
        assertThat(responseOutputItem.shellCall()).isEmpty
        assertThat(responseOutputItem.shellCallOutput()).isEmpty
        assertThat(responseOutputItem.applyPatchCall()).isEmpty
        assertThat(responseOutputItem.applyPatchCallOutput()).isEmpty
        assertThat(responseOutputItem.mcpCall()).isEmpty
        assertThat(responseOutputItem.mcpListTools()).isEmpty
        assertThat(responseOutputItem.mcpApprovalRequest()).isEmpty
        assertThat(responseOutputItem.mcpApprovalResponse()).isEmpty
        assertThat(responseOutputItem.customToolCall()).isEmpty
        assertThat(responseOutputItem.customToolCallOutput()).contains(customToolCallOutput)
    }

    @Test
    fun ofCustomToolCallOutputRoundtrip() {
        val jsonMapper = jsonMapper()
        val responseOutputItem =
            ResponseOutputItem.ofCustomToolCallOutput(
                ResponseCustomToolCallOutputItem.builder()
                    .callId("call_id")
                    .output("string")
                    .id("id")
                    .status(ResponseCustomToolCallOutputItem.Status.IN_PROGRESS)
                    .createdBy("created_by")
                    .build()
            )

        val roundtrippedResponseOutputItem =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(responseOutputItem),
                jacksonTypeRef<ResponseOutputItem>(),
            )

        assertThat(roundtrippedResponseOutputItem).isEqualTo(responseOutputItem)
    }

    enum class IncompatibleJsonShapeTestCase(val value: JsonValue) {
        BOOLEAN(JsonValue.from(false)),
        STRING(JsonValue.from("invalid")),
        INTEGER(JsonValue.from(-1)),
        FLOAT(JsonValue.from(3.14)),
        ARRAY(JsonValue.from(listOf("invalid", "array"))),
    }

    @ParameterizedTest
    @EnumSource
    fun incompatibleJsonShapeDeserializesToUnknown(testCase: IncompatibleJsonShapeTestCase) {
        val responseOutputItem =
            jsonMapper().convertValue(testCase.value, jacksonTypeRef<ResponseOutputItem>())

        val e = assertThrows<OpenAIInvalidDataException> { responseOutputItem.validate() }
        assertThat(e).hasMessageStartingWith("Unknown ")
    }
}
