// File generated from our OpenAPI spec by Stainless.

package com.openai.models

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

class ChatCompletionCreateParamsTest {

    @Test
    fun createChatCompletionCreateParams() {
        ChatCompletionCreateParams.builder()
            .addMessage(
                ChatCompletionDeveloperMessageParam.builder()
                    .content("string")
                    .role(ChatCompletionDeveloperMessageParam.Role.DEVELOPER)
                    .name("name")
                    .build()
            )
            .model(ChatModel.O1)
            .audio(
                ChatCompletionAudioParam.builder()
                    .format(ChatCompletionAudioParam.Format.WAV)
                    .voice(ChatCompletionAudioParam.Voice.ALLOY)
                    .build()
            )
            .frequencyPenalty(-2.0)
            .functionCall(ChatCompletionCreateParams.FunctionCall.Behavior.NONE)
            .addFunction(
                ChatCompletionCreateParams.Function.builder()
                    .name("name")
                    .description("description")
                    .parameters(
                        FunctionParameters.builder()
                            .putAdditionalProperty("foo", JsonValue.from("bar"))
                            .build()
                    )
                    .build()
            )
            .logitBias(
                ChatCompletionCreateParams.LogitBias.builder()
                    .putAdditionalProperty("foo", JsonValue.from(0))
                    .build()
            )
            .logprobs(true)
            .maxCompletionTokens(0L)
            .maxTokens(0L)
            .metadata(
                ChatCompletionCreateParams.Metadata.builder()
                    .putAdditionalProperty("foo", JsonValue.from("string"))
                    .build()
            )
            .addModality(ChatCompletionModality.TEXT)
            .n(1L)
            .parallelToolCalls(true)
            .prediction(
                ChatCompletionPredictionContent.builder()
                    .content("string")
                    .type(ChatCompletionPredictionContent.Type.CONTENT)
                    .build()
            )
            .presencePenalty(-2.0)
            .reasoningEffort(ChatCompletionReasoningEffort.LOW)
            .responseFormat(ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build())
            .seed(-9007199254740991L)
            .serviceTier(ChatCompletionCreateParams.ServiceTier.AUTO)
            .stop("string")
            .store(true)
            .streamOptions(ChatCompletionStreamOptions.builder().includeUsage(true).build())
            .temperature(1.0)
            .toolChoice(ChatCompletionToolChoiceOption.Behavior.NONE)
            .addTool(
                ChatCompletionTool.builder()
                    .function(
                        FunctionDefinition.builder()
                            .name("name")
                            .description("description")
                            .parameters(
                                FunctionParameters.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("bar"))
                                    .build()
                            )
                            .strict(true)
                            .build()
                    )
                    .type(ChatCompletionTool.Type.FUNCTION)
                    .build()
            )
            .topLogprobs(0L)
            .topP(1.0)
            .user("user-1234")
            .build()
    }

    @Test
    fun getBody() {
        val params =
            ChatCompletionCreateParams.builder()
                .addMessage(
                    ChatCompletionDeveloperMessageParam.builder()
                        .content("string")
                        .role(ChatCompletionDeveloperMessageParam.Role.DEVELOPER)
                        .name("name")
                        .build()
                )
                .model(ChatModel.O1)
                .audio(
                    ChatCompletionAudioParam.builder()
                        .format(ChatCompletionAudioParam.Format.WAV)
                        .voice(ChatCompletionAudioParam.Voice.ALLOY)
                        .build()
                )
                .frequencyPenalty(-2.0)
                .functionCall(ChatCompletionCreateParams.FunctionCall.Behavior.NONE)
                .addFunction(
                    ChatCompletionCreateParams.Function.builder()
                        .name("name")
                        .description("description")
                        .parameters(
                            FunctionParameters.builder()
                                .putAdditionalProperty("foo", JsonValue.from("bar"))
                                .build()
                        )
                        .build()
                )
                .logitBias(
                    ChatCompletionCreateParams.LogitBias.builder()
                        .putAdditionalProperty("foo", JsonValue.from(0))
                        .build()
                )
                .logprobs(true)
                .maxCompletionTokens(0L)
                .maxTokens(0L)
                .metadata(
                    ChatCompletionCreateParams.Metadata.builder()
                        .putAdditionalProperty("foo", JsonValue.from("string"))
                        .build()
                )
                .addModality(ChatCompletionModality.TEXT)
                .n(1L)
                .parallelToolCalls(true)
                .prediction(
                    ChatCompletionPredictionContent.builder()
                        .content("string")
                        .type(ChatCompletionPredictionContent.Type.CONTENT)
                        .build()
                )
                .presencePenalty(-2.0)
                .reasoningEffort(ChatCompletionReasoningEffort.LOW)
                .responseFormat(
                    ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build()
                )
                .seed(-9007199254740991L)
                .serviceTier(ChatCompletionCreateParams.ServiceTier.AUTO)
                .stop("string")
                .store(true)
                .streamOptions(ChatCompletionStreamOptions.builder().includeUsage(true).build())
                .temperature(1.0)
                .toolChoice(ChatCompletionToolChoiceOption.Behavior.NONE)
                .addTool(
                    ChatCompletionTool.builder()
                        .function(
                            FunctionDefinition.builder()
                                .name("name")
                                .description("description")
                                .parameters(
                                    FunctionParameters.builder()
                                        .putAdditionalProperty("foo", JsonValue.from("bar"))
                                        .build()
                                )
                                .strict(true)
                                .build()
                        )
                        .type(ChatCompletionTool.Type.FUNCTION)
                        .build()
                )
                .topLogprobs(0L)
                .topP(1.0)
                .user("user-1234")
                .build()
        val body = params.getBody()
        assertThat(body).isNotNull
        assertThat(body.messages())
            .isEqualTo(
                listOf(
                    ChatCompletionMessageParam.ofChatCompletionDeveloperMessageParam(
                        ChatCompletionDeveloperMessageParam.builder()
                            .content("string")
                            .role(ChatCompletionDeveloperMessageParam.Role.DEVELOPER)
                            .name("name")
                            .build()
                    )
                )
            )
        assertThat(body.model()).isEqualTo(ChatModel.O1)
        assertThat(body.audio())
            .contains(
                ChatCompletionAudioParam.builder()
                    .format(ChatCompletionAudioParam.Format.WAV)
                    .voice(ChatCompletionAudioParam.Voice.ALLOY)
                    .build()
            )
        assertThat(body.frequencyPenalty()).contains(-2.0)
        assertThat(body.functionCall())
            .contains(
                ChatCompletionCreateParams.FunctionCall.ofBehavior(
                    ChatCompletionCreateParams.FunctionCall.Behavior.NONE
                )
            )
        assertThat(body.functions())
            .contains(
                listOf(
                    ChatCompletionCreateParams.Function.builder()
                        .name("name")
                        .description("description")
                        .parameters(
                            FunctionParameters.builder()
                                .putAdditionalProperty("foo", JsonValue.from("bar"))
                                .build()
                        )
                        .build()
                )
            )
        assertThat(body.logitBias())
            .contains(
                ChatCompletionCreateParams.LogitBias.builder()
                    .putAdditionalProperty("foo", JsonValue.from(0))
                    .build()
            )
        assertThat(body.logprobs()).contains(true)
        assertThat(body.maxCompletionTokens()).contains(0L)
        assertThat(body.maxTokens()).contains(0L)
        assertThat(body.metadata())
            .contains(
                ChatCompletionCreateParams.Metadata.builder()
                    .putAdditionalProperty("foo", JsonValue.from("string"))
                    .build()
            )
        assertThat(body.modalities()).contains(listOf(ChatCompletionModality.TEXT))
        assertThat(body.n()).contains(1L)
        assertThat(body.parallelToolCalls()).contains(true)
        assertThat(body.prediction())
            .contains(
                ChatCompletionPredictionContent.builder()
                    .content("string")
                    .type(ChatCompletionPredictionContent.Type.CONTENT)
                    .build()
            )
        assertThat(body.presencePenalty()).contains(-2.0)
        assertThat(body.reasoningEffort()).contains(ChatCompletionReasoningEffort.LOW)
        assertThat(body.responseFormat())
            .contains(
                ChatCompletionCreateParams.ResponseFormat.ofResponseFormatText(
                    ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build()
                )
            )
        assertThat(body.seed()).contains(-9007199254740991L)
        assertThat(body.serviceTier()).contains(ChatCompletionCreateParams.ServiceTier.AUTO)
        assertThat(body.stop()).contains(ChatCompletionCreateParams.Stop.ofString("string"))
        assertThat(body.store()).contains(true)
        assertThat(body.streamOptions())
            .contains(ChatCompletionStreamOptions.builder().includeUsage(true).build())
        assertThat(body.temperature()).contains(1.0)
        assertThat(body.toolChoice())
            .contains(
                ChatCompletionToolChoiceOption.ofBehavior(
                    ChatCompletionToolChoiceOption.Behavior.NONE
                )
            )
        assertThat(body.tools())
            .contains(
                listOf(
                    ChatCompletionTool.builder()
                        .function(
                            FunctionDefinition.builder()
                                .name("name")
                                .description("description")
                                .parameters(
                                    FunctionParameters.builder()
                                        .putAdditionalProperty("foo", JsonValue.from("bar"))
                                        .build()
                                )
                                .strict(true)
                                .build()
                        )
                        .type(ChatCompletionTool.Type.FUNCTION)
                        .build()
                )
            )
        assertThat(body.topLogprobs()).contains(0L)
        assertThat(body.topP()).contains(1.0)
        assertThat(body.user()).contains("user-1234")
    }

    @Test
    fun getBodyWithoutOptionalFields() {
        val params =
            ChatCompletionCreateParams.builder()
                .addMessage(
                    ChatCompletionDeveloperMessageParam.builder()
                        .content("string")
                        .role(ChatCompletionDeveloperMessageParam.Role.DEVELOPER)
                        .build()
                )
                .model(ChatModel.O1)
                .build()
        val body = params.getBody()
        assertThat(body).isNotNull
        assertThat(body.messages())
            .isEqualTo(
                listOf(
                    ChatCompletionMessageParam.ofChatCompletionDeveloperMessageParam(
                        ChatCompletionDeveloperMessageParam.builder()
                            .content("string")
                            .role(ChatCompletionDeveloperMessageParam.Role.DEVELOPER)
                            .build()
                    )
                )
            )
        assertThat(body.model()).isEqualTo(ChatModel.O1)
    }
}
