package com.correx.core.tools.contract

import com.correx.core.approvals.Tier
import com.correx.core.events.events.ToolRequest
import com.correx.core.events.types.SessionId
import com.correx.core.events.types.StageId
import com.correx.core.events.types.ToolInvocationId
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs

class ToolContractTest {

    private val stubTool = object : Tool {
        override val name: String = "stub"
        override val description: String = "Stub tool for testing"
        override val parametersSchema: JsonObject = buildJsonObject {}
        override val tier: Tier = Tier.T0
        override val requiredCapabilities: Set<ToolCapability> = emptySet()
        override fun validateRequest(request: ToolRequest): ValidationResult = ValidationResult.Valid
    }

    private val request = ToolRequest(
        invocationId = ToolInvocationId("inv-1"),
        sessionId = SessionId("s-1"),
        stageId = StageId("st-1"),
        toolName = "stub"
    )

    @Test
    fun `stub tool returns Valid for any request`() {
        assertIs<ValidationResult.Valid>(stubTool.validateRequest(request))
    }

    @Test
    fun `ValidationResult Invalid carries reason`() {
        val result = ValidationResult.Invalid("missing required parameter")
        assertIs<ValidationResult.Invalid>(result)
        assertEquals("missing required parameter", result.reason)
    }

    @Test
    fun `tool exposes name tier and capabilities`() {
        assertEquals("stub", stubTool.name)
        assertEquals(Tier.T0, stubTool.tier)
        assertEquals(emptySet(), stubTool.requiredCapabilities)
    }
}
