using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MultiWheelC.TrajectoryPlanning.PathSmoothing.Output.Visualization;

/// <summary>报告导出结果的稳定状态。</summary>
public enum SmoothingReportExportStatus
{
    Success,
    InvalidInput,
    FontUnavailable,
    Failed,
}

/// <summary>六张常规 SVG、六张常规 PNG 与一个 CSV 的发布结果；增强模型携带诊断序列时追加可选 07-local-g2-diagnostic-candidate，失败时不返回部分输出路径。</summary>
public sealed class SmoothingReportExportResult
{
    internal SmoothingReportExportResult(SmoothingReportExportStatus status, string reason, IReadOnlyList<string> svgPaths, IReadOnlyList<string> pngPaths, string csvPath)
    {
        Status = status;
        Reason = reason ?? string.Empty;
        SvgPaths = Copy(svgPaths);
        PngPaths = Copy(pngPaths);
        CsvPath = csvPath ?? string.Empty;
    }

    public SmoothingReportExportStatus Status { get; }
    public string Reason { get; }
    public IReadOnlyList<string> SvgPaths { get; }
    public IReadOnlyList<string> PngPaths { get; }
    public string CsvPath { get; }

    internal static SmoothingReportExportResult Success(IReadOnlyList<string> svgPaths, IReadOnlyList<string> pngPaths, string csvPath)
    {
        return new SmoothingReportExportResult(SmoothingReportExportStatus.Success, string.Empty, svgPaths, pngPaths, csvPath);
    }

    internal static SmoothingReportExportResult Failure(SmoothingReportExportStatus status, string reason)
    {
        return new SmoothingReportExportResult(status, reason, new string[0], new string[0], string.Empty);
    }

    private static IReadOnlyList<string> Copy(IReadOnlyList<string> source)
    {
        var copy = new List<string>(source == null ? 0 : source.Count);
        if (source != null) for (int index = 0; index < source.Count; index++) copy.Add(source[index] ?? string.Empty);
        return new ReadOnlyCollection<string>(copy);
    }
}
