package com.optix.android.tools.registry

import com.optix.android.domain.model.ToolCategory
import com.optix.android.domain.model.ToolMetadata
import javax.inject.Inject
import javax.inject.Singleton

/**
 * Central registry for all Optix tools.
 *
 * Populated at app startup by [com.optix.android.di.ToolModule].
 * Consumed by:
 *  - ViewModels (list tools by category for UI)
 *  - AiBridge (build OpenAI-style schemas for tool calling)
 *  - ToolExecutionEngine (look up tool instance by name)
 */
@Singleton
class ToolRegistry @Inject constructor() {

    private val tools = mutableMapOf<String, BaseTool>()

    fun register(tool: BaseTool) {
        tools[tool.metadata.name] = tool
    }

    fun get(name: String): BaseTool? = tools[name]

    fun getAll(): List<BaseTool> = tools.values.toList()

    fun getByCategory(category: ToolCategory): List<BaseTool> =
        tools.values.filter { it.metadata.category == category }

    fun getAllMetadata(): List<ToolMetadata> = tools.values.map { it.metadata }

    fun getMetadataByCategory(category: ToolCategory): List<ToolMetadata> =
        getByCategory(category).map { it.metadata }

    fun listNames(): List<String> = tools.keys.toList()

    val toolCount: Int get() = tools.size
}
