using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using System.Windows.Media;

namespace ProximaAnalizer.Data;

internal partial class LineCollection : ObservableObject
{
    public LineCollection()
    {
        this.LinesDash.Add(new("FF00FF", [2, 2]));
        this.LinesDash.Add(new("4B0082", [2, 2]));
        this.LinesDash.Add(new("7B68EE", [2, 2]));
        this.LinesDash.Add(new("0000FF", [2, 2]));
        this.LinesDash.Add(new("1E90FF", [2, 2]));
        this.LinesDash.Add(new("32CD32", [2, 2]));
        this.LinesDash.Add(new("A0522D", [2, 2]));
        this.LinesDash.Add(new("FF8C00", [2, 2]));
        this.LinesDash.Add(new("FF0000", [2, 2]));
        this.LinesDash.Add(new("696969", [2, 2]));

        this.LinesSolid.Add(new("FF00FF", [2, 0]));
        this.LinesSolid.Add(new("4B0082", [2, 0]));
        this.LinesSolid.Add(new("7B68EE", [2, 0]));
        this.LinesSolid.Add(new("0000FF", [2, 0]));
        this.LinesSolid.Add(new("1E90FF", [2, 0]));
        this.LinesSolid.Add(new("32CD32", [2, 0]));
        this.LinesSolid.Add(new("A0522D", [2, 0]));
        this.LinesSolid.Add(new("FF8C00", [2, 0]));
        this.LinesSolid.Add(new("FF0000", [2, 0]));
        this.LinesSolid.Add(new("696969", [2, 0]));
    }

    [ObservableProperty]
    private ObservableCollection<LineType> _LinesSolid = [];

    [ObservableProperty]
    private ObservableCollection<LineType> _LinesDash = [];

}

internal partial class LineType : ObservableObject
{
    public LineType(string color, DoubleCollection dash)
    {
        this.HexRGB = color;
        this.DashArray = dash;
        if (dash[1] != 0)
            LinePattern = ScottPlot.LinePattern.DenselyDashed;
        else
            LinePattern = ScottPlot.LinePattern.Solid;
    }

    [ObservableProperty]
    private bool _IsEnable = true;
    public ScottPlot.LinePattern LinePattern { get; }

    private string? _hex;
    public string? HexRGB
    {
        get { return _hex; }
        set
        {
            _hex = value;
            this.Brush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#" + _hex));
        }
    }

    [JsonIgnore]
    public Brush? Brush { get; set; }
    public DoubleCollection? DashArray { get; set; }
}