using System;
using System.Collections.Generic;
namespace io.github.hatayama.uLoopMCP
{
///
/// Factory for creating and managing MCP configuration services
/// Centralizes configuration service creation and caching
/// Related classes:
/// - McpConfigService: Configuration service for specific editor types
/// - McpConfigRepository: Repository for configuration data
/// - McpEditorType: Enumeration of supported editor types
///
public class McpConfigServiceFactory
{
private readonly Dictionary _configServices;
public McpConfigServiceFactory()
{
_configServices = new Dictionary();
InitializeAllServices();
}
///
/// Get configuration service for specified editor type
///
/// Editor type
/// Configuration service
/// Thrown when unsupported editor type is specified
public IMcpConfigService GetConfigService(McpEditorType editorType)
{
if (_configServices.TryGetValue(editorType, out IMcpConfigService service))
{
return service;
}
throw new ArgumentException($"Unsupported editor type: {editorType}");
}
///
/// Get all available configuration services
///
/// Read-only collection of all configuration services
public IReadOnlyDictionary GetAllConfigServices()
{
return _configServices;
}
///
/// Initialize all configuration services
/// Automatically creates services for all defined McpEditorType enum values
///
private void InitializeAllServices()
{
McpEditorType[] allEditorTypes = (McpEditorType[])Enum.GetValues(typeof(McpEditorType));
foreach (McpEditorType editorType in allEditorTypes)
{
IMcpConfigService service;
if (editorType == McpEditorType.Codex)
{
service = new CodexTomlConfigService();
}
else
{
McpConfigRepository repository = new();
service = new McpConfigService(repository, editorType);
}
_configServices[editorType] = service;
}
}
}
}