using System.Collections.Generic;
using CounterDrone.Core.Reporting;
using Xunit;

namespace CounterDrone.Core.Tests
{
    public class MarkdownRendererTests
    {
        [Fact]
        public void Render_BasicStructure()
        {
            var data = new ReportData
            {
                Title = "测试报告",
                Header = new List<MetaItem>
                {
                    new() { Label = "任务名称", Value = "测试任务" },
                    new() { Label = "仿真耗时", Value = "10.0 秒" },
                },
                Sections = new List<ReportSection>
                {
                    new()
                    {
                        Title = "一、仿真结果",
                        Blocks = new List<ReportBlock>
                        {
                            new KeyValueBlock
                            {
                                LabelHeader = "统计项",
                                Items = new List<MetaItem>
                                {
                                    new() { Label = "无人机总数", Value = "3" },
                                    new() { Label = "被摧毁", Value = "3" },
                                },
                            },
                            new TextBlock { Text = "对抗结果：✅ 成功拦截", Bold = true },
                        },
                    },
                },
            };

            var md = new MarkdownRenderer().Render(data);

            Assert.Contains("# 测试报告", md);
            Assert.Contains("| 任务名称 | 测试任务 |", md);
            Assert.Contains("## 一、仿真结果", md);
            Assert.Contains("| 统计项 | 值 |", md);
            Assert.Contains("| 无人机总数 | 3 |", md);
            Assert.Contains("**对抗结果：✅ 成功拦截**", md);
        }

        [Fact]
        public void Render_TableBlock_WithCaption()
        {
            var data = new ReportData
            {
                Title = "测试",
                Sections = new List<ReportSection>
                {
                    new()
                    {
                        Title = "五、我方部署",
                        Blocks = new List<ReportBlock>
                        {
                            new TableBlock
                            {
                                Caption = "发射平台",
                                Headers = new[] { "#", "类型", "位置" },
                                Rows = new List<string[]>
                                {
                                    new[] { "#1", "地基", "(100, 0, 50)" },
                                    new[] { "#2", "空基", "(200, 500, 50)" },
                                },
                            },
                        },
                    },
                },
            };

            var md = new MarkdownRenderer().Render(data);

            Assert.Contains("### 发射平台", md);
            Assert.Contains("| # | 类型 | 位置 |", md);
            Assert.Contains("| #1 | 地基 | (100, 0, 50) |", md);
            Assert.Contains("| #2 | 空基 | (200, 500, 50) |", md);
        }

        [Fact]
        public void Render_TextBlock_Multiline()
        {
            var data = new ReportData
            {
                Title = "测试",
                Sections = new List<ReportSection>
                {
                    new()
                    {
                        Title = "七、时间线",
                        Blocks = new List<ReportBlock>
                        {
                            new TextBlock { Text = "- 第一行\n- 第二行" },
                        },
                    },
                },
            };

            var md = new MarkdownRenderer().Render(data);

            Assert.Contains("- 第一行", md);
            Assert.Contains("- 第二行", md);
        }
    }
}
