namespace HistoryView.Converters;

internal class IAlarmLastConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (parameter is null)
            return default;

        if (value is not IEnumerable<AlarmInfo> enums)
            return default;

        AlarmInfo? alarm = enums.LastOrDefault();
        if (alarm is null)
            return default;

        return parameter switch
        {
            "ChannelName" => alarm.ChannelName,
            "AlarmChannel" => alarm.AlarmChannel,
            "AlarmMini8" => alarm.AlarmMini8,
            "AlarmLevel" => alarm.AlarmLevel,
            "AlarmDetail" => alarm.AlarmDetail,
            "Date" => alarm.EventTime.ToString("yyyy-MM-dd"),
            "Time" => alarm.EventTime.ToString("HH:mm:ss"),
            _ => default
        };
    }

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