using LiteDB;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Windows;
using System.Windows.Media;

namespace Nodify.Calculator
{
    public enum ConnectorShape
    {
        Circle,
        Triangle,
        Square,
    }

    public class ConnectorViewModel : ObservableObject
    {
        private string? _title;
        public string? Title
        {
            get => _title;
            set => SetProperty(ref _title, value);
        }

        private double _value;
        public double Value
        {
            get => _value;
            set => SetProperty(ref _value, value)
                .Then(() => ValueObservers.ForEach(o => o.Value = value));
        }

        private ConnectorShape _shape;
        public ConnectorShape Shape
        {
            get => _shape;
            set => SetProperty(ref _shape, value);
        }

        private bool _isConnected;
        public bool IsConnected
        {
            get => _isConnected;
            set => SetProperty(ref _isConnected, value);
        }

        private bool _isInput;
        public bool IsInput
        {
            get => _isInput;
            set => SetProperty(ref _isInput, value);
        }

        private Point _anchor;
        public Point Anchor
        {
            get => _anchor;
            set => SetProperty(ref _anchor, value);
        }

        private System.Drawing.Color _color = System.Drawing.Color.DodgerBlue;
        public System.Drawing.Color ConnectorColor
        {
            set
            {
                _color = value;
            }
        }

        public Brush Color
        {
            get
            {
                var mediacolor = System.Windows.Media.Color.FromArgb
                    (
                        _color.A,
                        _color.R,
                        _color.G,
                        _color.B
                    );
                return ColorToSolidBrushConverter.Convert(mediacolor);
            }
        }

        [Newtonsoft.Json.JsonIgnore]
        [BsonIgnore]
        private OperationViewModel _operation = default!;
        [Newtonsoft.Json.JsonIgnore]
        [BsonIgnore]
        public OperationViewModel Operation
        {
            get => _operation;
            set => SetProperty(ref _operation, value);
        }

        [Newtonsoft.Json.JsonIgnore]
        [BsonIgnore]
        public List<ConnectorViewModel> ValueObservers { get; } = new List<ConnectorViewModel>();
    }
}
