using SWRIS.Models;
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Media;

namespace SWRIS.Converters
{
    public class ConnectivityFaultToColorConverter : IMultiValueConverter
    {
        private static readonly SolidColorBrush OnlineBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#00FF78"));
        private static readonly SolidColorBrush OfflineBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7886B2"));
        private static readonly SolidColorBrush FaultBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF0000"));
 
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values.Length < 2 || !(values[0] is bool isConnected) || !(values[1] is ObservableCollection<FaultDataModel> faults))
                return OfflineBrush;

            if (!isConnected)
                return OfflineBrush;

            if (faults != null && faults.Any(f => f != null)) // 检查非空故障
                return FaultBrush;

            return OnlineBrush;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
