using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using HC_APTBS.Models; namespace HC_APTBS.ViewModels { /// /// Represents the display state for one phase within the test list UI. /// Binds to a single row in the test phase grid. /// public sealed partial class PhaseRowViewModel : ObservableObject { /// Display name of the phase. [ObservableProperty] private string _name = string.Empty; /// True while this phase is actively executing. [ObservableProperty] private bool _isActive; /// True when the phase has completed and passed all criteria. [ObservableProperty] private bool _isPassed; /// True when the phase has completed but failed one or more criteria. [ObservableProperty] private bool _isFailed; /// Whether this phase is enabled for the current test run. [ObservableProperty] private bool _isEnabled = true; /// Short result string shown in the row (e.g. "PASS", "FAIL", "…"). [ObservableProperty] private string _resultText = string.Empty; } /// /// ViewModel for the TestDisplay user control. /// /// /// Shows the current test name, the list of phases with their pass/fail status, /// and the verbose status message from the bench service. /// /// public sealed partial class TestDisplayViewModel : ObservableObject { // ── Properties ──────────────────────────────────────────────────────────── /// Name of the test currently being executed (e.g. "F", "SVME"). [ObservableProperty] private string _testName = string.Empty; /// Current verbose status line from the bench service. [ObservableProperty] private string _statusText = string.Empty; /// Estimated total remaining time (seconds) for the entire test sequence. [ObservableProperty] private int _remainingSeconds; /// True while a test sequence is in progress. [ObservableProperty] private bool _isRunning; /// Phase rows shown in the phase list. public ObservableCollection Phases { get; } = new(); // ── Public API ──────────────────────────────────────────────────────────── /// /// Populates the phase list from a . /// Call when the active test changes. /// public void LoadTest(TestDefinition test) { TestName = test.Name; Phases.Clear(); foreach (var phase in test.Phases) { Phases.Add(new PhaseRowViewModel { Name = phase.Name, IsEnabled = phase.Enabled, ResultText = phase.Enabled ? "–" : "disabled" }); } } /// /// Marks a phase as active (running), clearing any previous active state. /// public void SetActivePhase(string phaseName) { StatusText = phaseName; foreach (var row in Phases) { row.IsActive = row.Name == phaseName; } } /// Updates a phase row with the result of a completed phase. public void SetPhaseResult(string phaseName, bool passed) { foreach (var row in Phases) { if (row.Name != phaseName) continue; row.IsActive = false; row.IsPassed = passed; row.IsFailed = !passed; row.ResultText = passed ? "PASS" : "FAIL"; break; } } /// Clears all phase result states for a fresh test run. public void ResetResults() { foreach (var row in Phases) { row.IsActive = false; row.IsPassed = false; row.IsFailed = false; row.ResultText = row.IsEnabled ? "–" : "disabled"; } } } }