namespace DeviceManagement.Controls;

public partial class DevicePlot : UserControl
{
    public DevicePlot()
    {
        InitializeComponent();
    }

    public DeviceInfo_VM DeviceInfo
    {
        get { return (DeviceInfo_VM)GetValue(DeviceInfoProperty); }
        set { SetValue(DeviceInfoProperty, value); }
    }

    public static readonly DependencyProperty DeviceInfoProperty =
        DependencyProperty.Register("DeviceInfo", typeof(DeviceInfo_VM), typeof(DevicePlot), new PropertyMetadata(default));

    public ICommand SettingCommand
    {
        get { return (ICommand)GetValue(SettingCommandProperty); }
        set { SetValue(SettingCommandProperty, value); }
    }

    public static readonly DependencyProperty SettingCommandProperty =
        DependencyProperty.Register("SettingCommand", typeof(ICommand), typeof(DevicePlot), new PropertyMetadata(default));

    public ICommand RemoteControlCommand
    {
        get { return (ICommand)GetValue(RemoteControlCommandProperty); }
        set { SetValue(RemoteControlCommandProperty, value); }
    }

    public static readonly DependencyProperty RemoteControlCommandProperty =
        DependencyProperty.Register("RemoteControlCommand", typeof(ICommand), typeof(DevicePlot), new PropertyMetadata(default));

    public ICommand DeleteCommand
    {
        get { return (ICommand)GetValue(DeleteCommandProperty); }
        set { SetValue(DeleteCommandProperty, value); }
    }

    public static readonly DependencyProperty DeleteCommandProperty =
        DependencyProperty.Register("DeleteCommand", typeof(ICommand), typeof(DevicePlot), new PropertyMetadata(default));



    public ICommand DetailCommand
    {
        get { return (ICommand)GetValue(DetailCommandProperty); }
        set { SetValue(DetailCommandProperty, value); }
    }

    public static readonly DependencyProperty DetailCommandProperty =
        DependencyProperty.Register("DetailCommand", typeof(ICommand), typeof(DevicePlot), new PropertyMetadata(default));
}

internal class DeviceImageConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not DeviceModel deviceModel)
            return null;

        return deviceModel switch
        {
            DeviceModel.JetKepler => new BitmapImage(new Uri("/DeviceManagement;component/Resources/Kepler.png", UriKind.Relative)),
            DeviceModel.Proxima => new BitmapImage(new Uri("/DeviceManagement;component/Resources/Furnace.png", UriKind.Relative)),
            _ => null
        };

    }

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

internal class ConnectToImageConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is not bool connected)
            return default;

        return connected switch
        {
            true => Application.Current.Resources["Icon_Connected"],
            false => Application.Current.Resources["lan_disconnectDrawingImage"]
        };

    }

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