// File generated from our OpenAPI spec by Stainless.

package com.openai.services.async.audio

import com.openai.TestServerExtension
import com.openai.client.okhttp.OpenAIOkHttpClientAsync
import com.openai.models.audio.AudioModel
import com.openai.models.audio.AudioResponseFormat
import com.openai.models.audio.transcriptions.TranscriptionCreateParams
import com.openai.models.audio.transcriptions.TranscriptionInclude
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(TestServerExtension::class)
internal class TranscriptionServiceAsyncTest {

    @Test
    fun create() {
        val client =
            OpenAIOkHttpClientAsync.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val transcriptionServiceAsync = client.audio().transcriptions()

        val transcriptionFuture =
            transcriptionServiceAsync.create(
                TranscriptionCreateParams.builder()
                    .file("Example data".byteInputStream())
                    .model(AudioModel.GPT_4O_TRANSCRIBE)
                    .chunkingStrategyAuto()
                    .addInclude(TranscriptionInclude.LOGPROBS)
                    .addKnownSpeakerName("string")
                    .addKnownSpeakerReference("string")
                    .language("language")
                    .prompt("prompt")
                    .responseFormat(AudioResponseFormat.JSON)
                    .temperature(0.0)
                    .addTimestampGranularity(TranscriptionCreateParams.TimestampGranularity.WORD)
                    .build()
            )

        val transcription = transcriptionFuture.get()
        transcription.validate()
    }

    @Disabled("Prism does not support SSE streaming mock responses")
    @Test
    fun createStreaming() {
        val client =
            OpenAIOkHttpClientAsync.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .build()
        val transcriptionServiceAsync = client.audio().transcriptions()

        val transcriptionStreamResponse =
            transcriptionServiceAsync.createStreaming(
                TranscriptionCreateParams.builder()
                    .file("Example data".byteInputStream())
                    .model(AudioModel.GPT_4O_TRANSCRIBE)
                    .chunkingStrategyAuto()
                    .addInclude(TranscriptionInclude.LOGPROBS)
                    .addKnownSpeakerName("string")
                    .addKnownSpeakerReference("string")
                    .language("language")
                    .prompt("prompt")
                    .responseFormat(AudioResponseFormat.JSON)
                    .temperature(0.0)
                    .addTimestampGranularity(TranscriptionCreateParams.TimestampGranularity.WORD)
                    .build()
            )

        val onCompleteFuture =
            transcriptionStreamResponse
                .subscribe { transcription -> transcription.validate() }
                .onCompleteFuture()
        onCompleteFuture.get()
    }
}
