using System;
using System.Globalization;
using System.Windows.Data;

namespace NavisworksTransport.UI.WPF.Converters
{
    /// <summary>
    /// 空值转短横线转换器
    /// </summary>
    public class NullToDashConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 如果值为null或空字符串，返回"-"
            if (value == null || string.IsNullOrEmpty(value.ToString()))
            {
                return "-";
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }

    /// <summary>
    /// 布尔值转"*"/""转换器
    /// </summary>
    public class BooleanToYesNoConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool boolValue)
            {
                // DetectAllObjects = true 表示检测所有物体（自动），不显示*
                // DetectAllObjects = false 表示手工指定了检测对象，显示*
                return !boolValue ? "*" : "";
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string strValue)
            {
                return strValue != "*";
            }
            return true;
        }
    }
}