// File generated from our OpenAPI spec by Stainless.

package com.openai.models.realtime

import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.openai.core.JsonValue
import com.openai.core.jsonMapper
import com.openai.models.responses.ResponsePrompt
import com.openai.models.responses.ToolChoiceOptions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

internal class SessionUpdateEventTest {

    @Test
    fun create() {
        val sessionUpdateEvent =
            SessionUpdateEvent.builder()
                .session(
                    RealtimeSessionCreateRequest.builder()
                        .model(RealtimeSessionCreateRequest.Model.GPT_REALTIME)
                        .audio(
                            RealtimeAudioConfig.builder()
                                .input(
                                    RealtimeAudioConfig.Input.builder()
                                        .format(RealtimeAudioConfig.Input.Format.PCM16)
                                        .noiseReduction(
                                            RealtimeAudioConfig.Input.NoiseReduction.builder()
                                                .type(
                                                    RealtimeAudioConfig.Input.NoiseReduction.Type
                                                        .NEAR_FIELD
                                                )
                                                .build()
                                        )
                                        .transcription(
                                            RealtimeAudioConfig.Input.Transcription.builder()
                                                .language("language")
                                                .model(
                                                    RealtimeAudioConfig.Input.Transcription.Model
                                                        .WHISPER_1
                                                )
                                                .prompt("prompt")
                                                .build()
                                        )
                                        .turnDetection(
                                            RealtimeAudioConfig.Input.TurnDetection.builder()
                                                .createResponse(true)
                                                .eagerness(
                                                    RealtimeAudioConfig.Input.TurnDetection
                                                        .Eagerness
                                                        .LOW
                                                )
                                                .idleTimeoutMs(0L)
                                                .interruptResponse(true)
                                                .prefixPaddingMs(0L)
                                                .silenceDurationMs(0L)
                                                .threshold(0.0)
                                                .type(
                                                    RealtimeAudioConfig.Input.TurnDetection.Type
                                                        .SERVER_VAD
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .output(
                                    RealtimeAudioConfig.Output.builder()
                                        .format(RealtimeAudioConfig.Output.Format.PCM16)
                                        .speed(0.25)
                                        .voice(RealtimeAudioConfig.Output.Voice.ALLOY)
                                        .build()
                                )
                                .build()
                        )
                        .clientSecret(
                            RealtimeClientSecretConfig.builder()
                                .expiresAfter(
                                    RealtimeClientSecretConfig.ExpiresAfter.builder()
                                        .anchor(
                                            RealtimeClientSecretConfig.ExpiresAfter.Anchor
                                                .CREATED_AT
                                        )
                                        .seconds(0L)
                                        .build()
                                )
                                .build()
                        )
                        .addInclude(
                            RealtimeSessionCreateRequest.Include
                                .ITEM_INPUT_AUDIO_TRANSCRIPTION_LOGPROBS
                        )
                        .instructions("instructions")
                        .maxOutputTokens(0L)
                        .addOutputModality(RealtimeSessionCreateRequest.OutputModality.TEXT)
                        .prompt(
                            ResponsePrompt.builder()
                                .id("id")
                                .variables(
                                    ResponsePrompt.Variables.builder()
                                        .putAdditionalProperty("foo", JsonValue.from("string"))
                                        .build()
                                )
                                .version("version")
                                .build()
                        )
                        .temperature(0.0)
                        .toolChoice(ToolChoiceOptions.NONE)
                        .addTool(
                            RealtimeToolsConfigUnion.Function.builder()
                                .description("description")
                                .name("name")
                                .parameters(JsonValue.from(mapOf<String, Any>()))
                                .type(RealtimeToolsConfigUnion.Function.Type.FUNCTION)
                                .build()
                        )
                        .tracingAuto()
                        .truncation(RealtimeTruncation.RealtimeTruncationStrategy.AUTO)
                        .build()
                )
                .eventId("event_id")
                .build()

        assertThat(sessionUpdateEvent.session())
            .isEqualTo(
                RealtimeSessionCreateRequest.builder()
                    .model(RealtimeSessionCreateRequest.Model.GPT_REALTIME)
                    .audio(
                        RealtimeAudioConfig.builder()
                            .input(
                                RealtimeAudioConfig.Input.builder()
                                    .format(RealtimeAudioConfig.Input.Format.PCM16)
                                    .noiseReduction(
                                        RealtimeAudioConfig.Input.NoiseReduction.builder()
                                            .type(
                                                RealtimeAudioConfig.Input.NoiseReduction.Type
                                                    .NEAR_FIELD
                                            )
                                            .build()
                                    )
                                    .transcription(
                                        RealtimeAudioConfig.Input.Transcription.builder()
                                            .language("language")
                                            .model(
                                                RealtimeAudioConfig.Input.Transcription.Model
                                                    .WHISPER_1
                                            )
                                            .prompt("prompt")
                                            .build()
                                    )
                                    .turnDetection(
                                        RealtimeAudioConfig.Input.TurnDetection.builder()
                                            .createResponse(true)
                                            .eagerness(
                                                RealtimeAudioConfig.Input.TurnDetection.Eagerness
                                                    .LOW
                                            )
                                            .idleTimeoutMs(0L)
                                            .interruptResponse(true)
                                            .prefixPaddingMs(0L)
                                            .silenceDurationMs(0L)
                                            .threshold(0.0)
                                            .type(
                                                RealtimeAudioConfig.Input.TurnDetection.Type
                                                    .SERVER_VAD
                                            )
                                            .build()
                                    )
                                    .build()
                            )
                            .output(
                                RealtimeAudioConfig.Output.builder()
                                    .format(RealtimeAudioConfig.Output.Format.PCM16)
                                    .speed(0.25)
                                    .voice(RealtimeAudioConfig.Output.Voice.ALLOY)
                                    .build()
                            )
                            .build()
                    )
                    .clientSecret(
                        RealtimeClientSecretConfig.builder()
                            .expiresAfter(
                                RealtimeClientSecretConfig.ExpiresAfter.builder()
                                    .anchor(
                                        RealtimeClientSecretConfig.ExpiresAfter.Anchor.CREATED_AT
                                    )
                                    .seconds(0L)
                                    .build()
                            )
                            .build()
                    )
                    .addInclude(
                        RealtimeSessionCreateRequest.Include.ITEM_INPUT_AUDIO_TRANSCRIPTION_LOGPROBS
                    )
                    .instructions("instructions")
                    .maxOutputTokens(0L)
                    .addOutputModality(RealtimeSessionCreateRequest.OutputModality.TEXT)
                    .prompt(
                        ResponsePrompt.builder()
                            .id("id")
                            .variables(
                                ResponsePrompt.Variables.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("string"))
                                    .build()
                            )
                            .version("version")
                            .build()
                    )
                    .temperature(0.0)
                    .toolChoice(ToolChoiceOptions.NONE)
                    .addTool(
                        RealtimeToolsConfigUnion.Function.builder()
                            .description("description")
                            .name("name")
                            .parameters(JsonValue.from(mapOf<String, Any>()))
                            .type(RealtimeToolsConfigUnion.Function.Type.FUNCTION)
                            .build()
                    )
                    .tracingAuto()
                    .truncation(RealtimeTruncation.RealtimeTruncationStrategy.AUTO)
                    .build()
            )
        assertThat(sessionUpdateEvent.eventId()).contains("event_id")
    }

    @Test
    fun roundtrip() {
        val jsonMapper = jsonMapper()
        val sessionUpdateEvent =
            SessionUpdateEvent.builder()
                .session(
                    RealtimeSessionCreateRequest.builder()
                        .model(RealtimeSessionCreateRequest.Model.GPT_REALTIME)
                        .audio(
                            RealtimeAudioConfig.builder()
                                .input(
                                    RealtimeAudioConfig.Input.builder()
                                        .format(RealtimeAudioConfig.Input.Format.PCM16)
                                        .noiseReduction(
                                            RealtimeAudioConfig.Input.NoiseReduction.builder()
                                                .type(
                                                    RealtimeAudioConfig.Input.NoiseReduction.Type
                                                        .NEAR_FIELD
                                                )
                                                .build()
                                        )
                                        .transcription(
                                            RealtimeAudioConfig.Input.Transcription.builder()
                                                .language("language")
                                                .model(
                                                    RealtimeAudioConfig.Input.Transcription.Model
                                                        .WHISPER_1
                                                )
                                                .prompt("prompt")
                                                .build()
                                        )
                                        .turnDetection(
                                            RealtimeAudioConfig.Input.TurnDetection.builder()
                                                .createResponse(true)
                                                .eagerness(
                                                    RealtimeAudioConfig.Input.TurnDetection
                                                        .Eagerness
                                                        .LOW
                                                )
                                                .idleTimeoutMs(0L)
                                                .interruptResponse(true)
                                                .prefixPaddingMs(0L)
                                                .silenceDurationMs(0L)
                                                .threshold(0.0)
                                                .type(
                                                    RealtimeAudioConfig.Input.TurnDetection.Type
                                                        .SERVER_VAD
                                                )
                                                .build()
                                        )
                                        .build()
                                )
                                .output(
                                    RealtimeAudioConfig.Output.builder()
                                        .format(RealtimeAudioConfig.Output.Format.PCM16)
                                        .speed(0.25)
                                        .voice(RealtimeAudioConfig.Output.Voice.ALLOY)
                                        .build()
                                )
                                .build()
                        )
                        .clientSecret(
                            RealtimeClientSecretConfig.builder()
                                .expiresAfter(
                                    RealtimeClientSecretConfig.ExpiresAfter.builder()
                                        .anchor(
                                            RealtimeClientSecretConfig.ExpiresAfter.Anchor
                                                .CREATED_AT
                                        )
                                        .seconds(0L)
                                        .build()
                                )
                                .build()
                        )
                        .addInclude(
                            RealtimeSessionCreateRequest.Include
                                .ITEM_INPUT_AUDIO_TRANSCRIPTION_LOGPROBS
                        )
                        .instructions("instructions")
                        .maxOutputTokens(0L)
                        .addOutputModality(RealtimeSessionCreateRequest.OutputModality.TEXT)
                        .prompt(
                            ResponsePrompt.builder()
                                .id("id")
                                .variables(
                                    ResponsePrompt.Variables.builder()
                                        .putAdditionalProperty("foo", JsonValue.from("string"))
                                        .build()
                                )
                                .version("version")
                                .build()
                        )
                        .temperature(0.0)
                        .toolChoice(ToolChoiceOptions.NONE)
                        .addTool(
                            RealtimeToolsConfigUnion.Function.builder()
                                .description("description")
                                .name("name")
                                .parameters(JsonValue.from(mapOf<String, Any>()))
                                .type(RealtimeToolsConfigUnion.Function.Type.FUNCTION)
                                .build()
                        )
                        .tracingAuto()
                        .truncation(RealtimeTruncation.RealtimeTruncationStrategy.AUTO)
                        .build()
                )
                .eventId("event_id")
                .build()

        val roundtrippedSessionUpdateEvent =
            jsonMapper.readValue(
                jsonMapper.writeValueAsString(sessionUpdateEvent),
                jacksonTypeRef<SessionUpdateEvent>(),
            )

        assertThat(roundtrippedSessionUpdateEvent).isEqualTo(sessionUpdateEvent)
    }
}
