using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using UnifiedFarmLauncher.Models; using UnifiedFarmLauncher.Services; namespace UnifiedFarmLauncher.ViewModels { public class MainWindowViewModel : ViewModelBase { private readonly ConfigService _configService; private WorkerConfig? _selectedWorker; private string _statusText = "Ready"; private string _selectedWorkerType = "All"; public MainWindowViewModel() { _configService = new ConfigService(); Workers = new ObservableCollection(); LoadWorkers(); } public ObservableCollection Workers { get; } public WorkerConfig? SelectedWorker { get => _selectedWorker; set { if (SetAndRaise(ref _selectedWorker, value)) { UpdateStatusText(); } } } public string StatusText { get => _statusText; set => SetAndRaise(ref _statusText, value); } public string SelectedWorkerType { get => _selectedWorkerType; set { if (SetAndRaise(ref _selectedWorkerType, value)) { LoadWorkers(); } } } public void LoadWorkers() { var config = _configService.Load(); Workers.Clear(); var workers = config.Workers; if (SelectedWorkerType != "All") { workers = workers.Where(w => { if (SelectedWorkerType == "SheepIt") return w.WorkerTypes.SheepIt != null; if (SelectedWorkerType == "Flamenco") return w.WorkerTypes.Flamenco != null; return true; }).ToList(); } foreach (var worker in workers) { Workers.Add(worker); } UpdateStatusText(); } private void UpdateStatusText() { if (SelectedWorker == null) { StatusText = $"Total workers: {Workers.Count}"; } else { StatusText = $"Selected: {SelectedWorker.Name} ({SelectedWorker.Ssh.Host}:{SelectedWorker.Ssh.Port})"; } } public void RefreshWorkers() { LoadWorkers(); } } }