using MarketAlly.AIPlugin.Refactoring.Plugins; using MarketAlly.AIPlugin.Refactoring.Services; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace MarketAlly.AIPlugin.Refactoring { /// /// Enhanced version of ReadmeGeneratorPlugin that integrates AI capabilities /// [AIPlugin("AIReadmeGenerator", "AI-powered README generator that creates intelligent, comprehensive documentation")] public class AIReadmeGeneratorPlugin : IAIPlugin { [AIParameter("Path to project directory or solution file", required: true)] public string ProjectPath { get; set; } [AIParameter("Type of project: auto, library, application, tool, maui", required: false)] public string ProjectType { get; set; } = "auto"; [AIParameter("Enable AI-powered content enhancement", required: false)] public bool EnableAIEnhancement { get; set; } = true; [AIParameter("Include AI-generated usage examples", required: false)] public bool AIGeneratedExamples { get; set; } = true; [AIParameter("Include AI-enhanced API documentation", required: false)] public bool AIEnhancedApiDocs { get; set; } = true; [AIParameter("Apply changes and create README.md file", required: false)] public bool ApplyChanges { get; set; } = false; public IReadOnlyDictionary SupportedParameters => new Dictionary { ["projectPath"] = typeof(string), ["projectpath"] = typeof(string), ["projectType"] = typeof(string), ["projecttype"] = typeof(string), ["enableAIEnhancement"] = typeof(bool), ["enableaienhancement"] = typeof(bool), ["aiGeneratedExamples"] = typeof(bool), ["aigeneratedexamples"] = typeof(bool), ["aiEnhancedApiDocs"] = typeof(bool), ["aienhancedapidocs"] = typeof(bool), ["applyChanges"] = typeof(bool), ["applychanges"] = typeof(bool) }; public async Task ExecuteAsync(IReadOnlyDictionary parameters) { try { // First, run the basic README generator var basicGenerator = new ReadmeGeneratorPlugin(); var basicResult = await basicGenerator.ExecuteAsync(parameters); if (!basicResult.Success) { return basicResult; } // If AI enhancement is disabled, return basic result bool enableAI = GetBoolParameter(parameters, "enableAIEnhancement", "enableaienhancement", true); if (!enableAI) { return basicResult; } // FIXED: Create registry instance properly (this is a simplified version) // In a real implementation, you'd inject this or get it from the calling context var tempRegistry = new AIPluginRegistry(null); // Pass null logger for now var aiService = new AIReadmeEnhancementService(tempRegistry, null); // For now, just return the basic result with AI enhancement flag // This can be enhanced later when Claude integration is ready var resultData = JsonSerializer.Deserialize>( JsonSerializer.Serialize(basicResult.Data)); resultData["AIEnhancementAvailable"] = true; resultData["AIEnhancementNote"] = "AI enhancement ready for Claude integration"; return new AIPluginResult(resultData); } catch (Exception ex) { return new AIPluginResult(ex, $"AI README generation failed: {ex.Message}"); } } private object GetParameterValue(IReadOnlyDictionary parameters, params string[] keys) { foreach (var key in keys) { if (parameters.TryGetValue(key, out var value)) return value; } return null; } private bool GetBoolParameter(IReadOnlyDictionary parameters, string key1, string key2, bool defaultValue) { var value = GetParameterValue(parameters, key1, key2); return value != null ? Convert.ToBoolean(value) : defaultValue; } } }