package com.correx.infrastructure.inference.commons

import com.correx.core.inference.InferenceProvider
import com.correx.core.inference.ProviderHealth

/**
 * Manages the lifecycle of models.
 */
interface ModelManager {
    /**
     * Loads a model and returns an InferenceProvider instance.
     * 
     * @param descriptor Model configuration
     * @return An InferenceProvider for the loaded model
     * @throws ModelLoadException if a different model is already loaded
     */
    suspend fun load(descriptor: ModelDescriptor): InferenceProvider

    /**
     * Ensures the model described by [descriptor] is the resident model, returning its provider.
     * A no-op load if that model is already current; otherwise loads it (evicting the previous
     * model). [load] is idempotent for the already-loaded model, so the default delegates to it.
     */
    suspend fun ensureLoaded(descriptor: ModelDescriptor): InferenceProvider = load(descriptor)

    /**
     * Unloads the currently loaded model.
     * 
     * @param modelId The model ID to unload
     * @throws ModelLoadException if no model is currently loaded
     */
    suspend fun unload(modelId: String)

    /**
     * Returns the descriptor of the currently loaded model, or null if none.
     */
    fun currentModel(): ModelDescriptor?

    /**
     * Health check for the current model.
     */
    fun healthCheck(): ProviderHealth
}
