package com.correx.core.artifacts.kind

import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull

class ArtifactKindRegistryTest {
    private val registry = DefaultArtifactKindRegistry()

    @Test
    fun `built-in kinds are registered`() {
        assertNotNull(registry.get("file_written"))
        assertNotNull(registry.get("process_result"))
    }

    @Test
    fun `get returns null for unknown kind`() {
        assertNull(registry.get("nonexistent"))
    }

    @Test
    fun `FileWrittenKind is not llmEmitted`() {
        assertEquals(false, registry.get("file_written")!!.llmEmitted)
    }

    @Test
    fun `ProcessResultKind is not llmEmitted`() {
        assertEquals(false, registry.get("process_result")!!.llmEmitted)
    }

    @Test
    fun `config-declared kind registers and exposes its declared schema`() {
        val schema = JsonSchema(
            type = "object",
            properties = mapOf("x" to JsonSchemaProperty(type = "string")),
            required = listOf("x"),
        )
        registry.register(ConfigArtifactKind(id = "custom", schema = schema, llmEmitted = true))

        val kind = registry.get("custom")
        assertNotNull(kind)
        assertEquals(true, kind!!.llmEmitted)
        assertEquals(schema, kind.deriveJsonSchema())
    }

    @Test
    fun `FileWrittenKind schema has required fields`() {
        val schema = FileWrittenKind.deriveJsonSchema()
        assertEquals("object", schema.type)
        assert("path" in schema.required)
        assert("content" in schema.required)
    }
}
