using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace IBKRTrader.Core.Workers;
///
/// ViewModel-Objekt für eine Zeile in dgv_workerlist.
/// Implementiert INotifyPropertyChanged für automatisches DataGridView-Binding.
///
public class WorkerInfo : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
private bool _active;
private string _type = "";
private string _module = "";
private string _workerName = "";
private DateTime? _lastRuntime;
private DateTime? _nextRuntime;
private string _runEvery = "";
private string _info = "";
private WorkerStatus _status = WorkerStatus.Idle;
// ─── Properties ───────────────────────────────────────────────────────────
public bool Active { get => _active; set => Set(ref _active, value); }
public string Type { get => _type; set => Set(ref _type, value); }
public string Module { get => _module; set => Set(ref _module, value); }
public string WorkerName { get => _workerName; set => Set(ref _workerName, value); }
public DateTime? LastRuntime { get => _lastRuntime; set => Set(ref _lastRuntime, value); }
public DateTime? NextRuntime { get => _nextRuntime; set => Set(ref _nextRuntime, value); }
public string RunEvery { get => _runEvery; set => Set(ref _runEvery, value); }
public string Info { get => _info; set => Set(ref _info, value); }
/// Interner Status – wird nicht direkt als DGV-Spalte verwendet,
/// aber steuert die Info-Spalte.
public WorkerStatus Status
{
get => _status;
set
{
if (!Set(ref _status, value)) return;
// Info-Text automatisch synchronisieren
if (value == WorkerStatus.Idle && string.IsNullOrWhiteSpace(_info))
Info = "Bereit";
}
}
// ─── Hilfsmethode ─────────────────────────────────────────────────────────
private bool Set(ref T field, T value, [CallerMemberName] string? prop = null)
{
if (EqualityComparer.Default.Equals(field, value)) return false;
field = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(prop));
return true;
}
}