using System; using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using HC_APTBS.Models; namespace HC_APTBS.ViewModels { /// /// Represents a single phase card within a test section. /// Displays the phase name, enable/disable toggle, operation values, /// and graphic result indicators. /// public sealed partial class PhaseCardViewModel : ObservableObject { // ── Identity ────────────────────────────────────────────────────────────── /// Display name of the phase (e.g. "1 - S_001"). [ObservableProperty] private string _name = string.Empty; /// True when failure in this phase halts the entire test sequence. [ObservableProperty] private bool _isCritical; // ── Enable/disable ──────────────────────────────────────────────────────── /// /// Whether this phase is included in the test run. /// Writing this property also updates the underlying /// and notifies the parent to recalculate its /// AllPhasesChecked state. /// [ObservableProperty] private bool _isEnabled = true; // ── Execution state ─────────────────────────────────────────────────────── /// True while this phase is actively executing. [ObservableProperty] private bool _isActive; /// True when the phase completed and passed all criteria. [ObservableProperty] private bool _isPassed; /// True when the phase completed but failed one or more criteria. [ObservableProperty] private bool _isFailed; /// Short result label shown in the card (e.g. "PASS", "FAIL", "-"). [ObservableProperty] private string _resultText = string.Empty; // ── Operation values visibility ─────────────────────────────────────────── /// /// Controls visibility of the operation values section (RPM, ME, FBKW). /// Bound from . /// [ObservableProperty] private bool _showOperationValues; // ── Collections ─────────────────────────────────────────────────────────── /// Send parameters displayed in the card (RPM, ME, FBKW, etc.). public ObservableCollection OperationValues { get; } = new(); /// Readiness conditions displayed in the card (temperature, etc.). public ObservableCollection ReadyValues { get; } = new(); /// Graphic result indicators, one per receive parameter. public ObservableCollection ResultIndicators { get; } = new(); // ── Back-references ─────────────────────────────────────────────────────── /// Back-reference to the model for writing enabled state changes. internal PhaseDefinition? Source { get; set; } /// /// Callback invoked when changes, so the parent /// can recalculate AllPhasesChecked. /// internal Action? EnabledChanged { get; set; } // ── Change handlers ─────────────────────────────────────────────────────── partial void OnIsEnabledChanged(bool value) { // Write back to the model. if (Source != null) Source.Enabled = value; ResultText = value ? "\u2013" : "disabled"; // Notify parent. EnabledChanged?.Invoke(this); } // ── Public API ──────────────────────────────────────────────────────────── /// Resets execution state for a new test run. public void Reset() { IsActive = false; IsPassed = false; IsFailed = false; ResultText = IsEnabled ? "\u2013" : "disabled"; foreach (var indicator in ResultIndicators) indicator.Reset(); } } }