// File generated from our OpenAPI spec by Stainless.

package com.openai.services.blocking.beta.chatkit

import com.openai.TestServerExtension
import com.openai.client.okhttp.OpenAIOkHttpClient
import com.openai.core.JsonValue
import com.openai.models.beta.chatkit.sessions.SessionCreateParams
import com.openai.models.beta.chatkit.threads.ChatSessionChatKitConfigurationParam
import com.openai.models.beta.chatkit.threads.ChatSessionExpiresAfterParam
import com.openai.models.beta.chatkit.threads.ChatSessionRateLimitsParam
import com.openai.models.beta.chatkit.threads.ChatSessionWorkflowParam
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

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

    @Test
    fun create() {
        val client =
            OpenAIOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .adminApiKey("My Admin API Key")
                .build()
        val sessionService = client.beta().chatkit().sessions()

        val chatSession =
            sessionService.create(
                SessionCreateParams.builder()
                    .user("x")
                    .workflow(
                        ChatSessionWorkflowParam.builder()
                            .id("id")
                            .stateVariables(
                                ChatSessionWorkflowParam.StateVariables.builder()
                                    .putAdditionalProperty("foo", JsonValue.from("string"))
                                    .build()
                            )
                            .tracing(
                                ChatSessionWorkflowParam.Tracing.builder().enabled(true).build()
                            )
                            .version("version")
                            .build()
                    )
                    .chatkitConfiguration(
                        ChatSessionChatKitConfigurationParam.builder()
                            .automaticThreadTitling(
                                ChatSessionChatKitConfigurationParam.AutomaticThreadTitling
                                    .builder()
                                    .enabled(true)
                                    .build()
                            )
                            .fileUpload(
                                ChatSessionChatKitConfigurationParam.FileUpload.builder()
                                    .enabled(true)
                                    .maxFileSize(1L)
                                    .maxFiles(1L)
                                    .build()
                            )
                            .history(
                                ChatSessionChatKitConfigurationParam.History.builder()
                                    .enabled(true)
                                    .recentThreads(1L)
                                    .build()
                            )
                            .build()
                    )
                    .expiresAfter(ChatSessionExpiresAfterParam.builder().seconds(1L).build())
                    .rateLimits(
                        ChatSessionRateLimitsParam.builder().maxRequestsPer1Minute(1L).build()
                    )
                    .build()
            )

        chatSession.validate()
    }

    @Test
    fun cancel() {
        val client =
            OpenAIOkHttpClient.builder()
                .baseUrl(TestServerExtension.BASE_URL)
                .apiKey("My API Key")
                .adminApiKey("My Admin API Key")
                .build()
        val sessionService = client.beta().chatkit().sessions()

        val chatSession = sessionService.cancel("cksess_123")

        chatSession.validate()
    }
}
