using System;
using System.Collections.Generic;

namespace TrajectoryPlanningVisualization;

public enum VisualizationLineStyle
{
    Solid,
    Dashed,
    Limit
}

public sealed class VisualizationSeries
{
    public VisualizationSeries(string id, string legend, VisualizationLineStyle lineStyle,
        IReadOnlyList<VisualizationPoint> points)
    {
        Id = VisualizationContract.RequireText(id, nameof(id));
        Legend = VisualizationContract.RequireText(legend, nameof(legend));
        LineStyle = lineStyle;
        Points = VisualizationContract.Copy(points, nameof(points));
    }

    public string Id { get; }
    public string Legend { get; }
    public VisualizationLineStyle LineStyle { get; }
    public IReadOnlyList<VisualizationPoint> Points { get; }
}

public sealed class VisualizationChartAnnotation
{
    public VisualizationChartAnnotation(string id, string kind, string labelChinese,
        double x, double? y = null)
    {
        Id = VisualizationContract.RequireText(id, nameof(id));
        Kind = VisualizationContract.RequireText(kind, nameof(kind));
        LabelChinese = VisualizationContract.RequireText(labelChinese, nameof(labelChinese));
        VisualizationContract.RequireFinite(x, nameof(x));
        VisualizationContract.RequireFinite(y, nameof(y));
        X = x;
        Y = y;
    }

    public string Id { get; }
    public string Kind { get; }
    public string LabelChinese { get; }
    public double X { get; }
    public double? Y { get; }
}

public sealed class VisualizationChart
{
    public VisualizationChart(string id, string chineseTitle, string xAxisLabel, string yAxisLabel,
        IReadOnlyList<VisualizationSeries> series, string noteChinese = "")
        : this(id, chineseTitle, xAxisLabel, yAxisLabel, series, noteChinese,
            Array.Empty<VisualizationChartAnnotation>())
    {
    }

    public VisualizationChart(string id, string chineseTitle, string xAxisLabel, string yAxisLabel,
        IReadOnlyList<VisualizationSeries> series, string noteChinese,
        IReadOnlyList<VisualizationChartAnnotation> annotations)
    {
        Id = VisualizationContract.RequireText(id, nameof(id));
        ChineseTitle = VisualizationContract.RequireText(chineseTitle, nameof(chineseTitle));
        XAxisLabel = VisualizationContract.RequireText(xAxisLabel, nameof(xAxisLabel));
        YAxisLabel = VisualizationContract.RequireText(yAxisLabel, nameof(yAxisLabel));
        Series = VisualizationContract.Copy(series, nameof(series));
        NoteChinese = VisualizationContract.RequireText(noteChinese, nameof(noteChinese));
        Annotations = VisualizationContract.Copy(annotations, nameof(annotations));
    }

    public string Id { get; }
    public string ChineseTitle { get; }
    public string XAxisLabel { get; }
    public string YAxisLabel { get; }
    public IReadOnlyList<VisualizationSeries> Series { get; }
    public string NoteChinese { get; }
    public IReadOnlyList<VisualizationChartAnnotation> Annotations { get; }
}
