package dev.mokksy.aimocks.gemini.springai

import dev.mokksy.aimocks.gemini.gemini
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import org.springframework.ai.chat.model.ChatResponse
import kotlin.test.Test
import kotlin.time.Duration.Companion.milliseconds

internal class GeminiChatCompletionSpringAiTest : AbstractGeminiSpringAiTest() {
    @Test
    fun `Should respond to generateContent`() {
        val systemMessage = "You are a helpful pirate. $seedValue"
        val systemInstruction = "Follow these rules: $systemMessage"
        gemini.generateContent {
            temperature = temperatureValue
            model = modelName
            project = projectId
            location = locationId
            systemMessageContains(systemMessage)
            userMessageContains("Just say 'Hello!'")
        } responds {
            content = "Ahoy there, matey! Hello!"
            finishReason = "stop"
            delay = 42.milliseconds
        }

        val response: ChatResponse? =
            prepareClientRequest(systemInstruction)
                .call()
                .chatResponse()

        response shouldNotBeNull {
            result shouldNotBeNull {
                metadata.finishReason shouldBe "STOP"
                output.text shouldBe "Ahoy there, matey! Hello!"
            }
        }
    }
}
