using System.Collections.Generic;
using UnityEngine;

namespace RedCircuit.AIAssistant
{
    /// <summary>
    /// 电路分析与建议，解析 AI 返回的电路方案并展示诊断报告。
    /// </summary>
    public class AICircuitAdvisor : MonoBehaviour
    {
        /// <summary>显示电路分析报告</summary>
        public void ShowReport(CircuitAnalysisReport report)
        {
            if (report == null) return;

            Debug.Log($"[AIAdvisor] 电路分析: {report.Summary}");
            Debug.Log($"[AIAdvisor] 元件数: {report.Metrics.ComponentCount}, 成本: {report.Metrics.TotalCost}, 最大延迟: {report.Metrics.MaxDelay} tick");

            foreach (var issue in report.Issues)
            {
                var icon = issue.Severity == IssueSeverity.Error ? "[ERROR]" : "[WARN]";
                Debug.Log($"[AIAdvisor] {icon} ({issue.Location.X},{issue.Location.Y}) {issue.Description}");
                if (!string.IsNullOrEmpty(issue.Suggestion))
                    Debug.Log($"[AIAdvisor]   -> 建议: {issue.Suggestion}");
            }

            foreach (var opt in report.Optimizations)
            {
                Debug.Log($"[AIAdvisor] [OPT] {opt.Description} ({opt.EstimatedImprovement})");
            }

            // TODO: 在 UI 上展示分析报告面板
        }

        /// <summary>显示电路搭建方案供用户选择</summary>
        public void ShowCircuitPlan(List<CircuitPlan> plans)
        {
            foreach (var plan in plans)
            {
                Debug.Log($"[AIAdvisor] 方案: {plan.Name} | 成本: {plan.Cost} | 延迟: {plan.Delay} tick | 元件: {plan.ComponentCount}");
                Debug.Log($"[AIAdvisor]   {plan.Description}");
            }
            // TODO: 在 UI 上展示方案对比卡片
        }

        /// <summary>高亮显示问题位置</summary>
        public void HighlightIssue(GridPosition location, IssueSeverity severity)
        {
            // TODO: 在画布上高亮显示问题格子
            // Error -> 红色边框, Warning -> 黄色边框
        }

        /// <summary>清除所有高亮</summary>
        public void ClearHighlights()
        {
            // TODO: 移除画布上的所有问题高亮
        }
    }
}
