| 1 | using CascadeIDE.Features.UiChrome; |
| 2 | |
| 3 | namespace CascadeIDE.ViewModels; |
| 4 | |
| 5 | internal readonly record struct UiModeGateContext( |
| 6 | UiModeFamily UiModeFamily, |
| 7 | bool AutonomousAgentTelemetryEnabled, |
| 8 | bool TerminalVisible, |
| 9 | bool HasDebugSession); |
| 10 | |
| 11 | internal interface IUiModeGateSpecification |
| 12 | { |
| 13 | bool IsSatisfiedBy(in UiModeGateContext context); |
| 14 | } |
| 15 | |
| 16 | internal sealed class UiModeFamilyGateSpecification(UiModeFamily family) : IUiModeGateSpecification |
| 17 | { |
| 18 | public bool IsSatisfiedBy(in UiModeGateContext context) => context.UiModeFamily == family; |
| 19 | } |
| 20 | |
| 21 | internal sealed class TelemetryEnabledGateSpecification : IUiModeGateSpecification |
| 22 | { |
| 23 | public bool IsSatisfiedBy(in UiModeGateContext context) => context.AutonomousAgentTelemetryEnabled; |
| 24 | } |
| 25 | |
| 26 | internal sealed class TerminalHiddenGateSpecification : IUiModeGateSpecification |
| 27 | { |
| 28 | public bool IsSatisfiedBy(in UiModeGateContext context) => !context.TerminalVisible; |
| 29 | } |
| 30 | |
| 31 | internal sealed class AndUiModeGateSpecification(params IUiModeGateSpecification[] specifications) : IUiModeGateSpecification |
| 32 | { |
| 33 | public bool IsSatisfiedBy(in UiModeGateContext context) |
| 34 | { |
| 35 | foreach (var specification in specifications) |
| 36 | { |
| 37 | if (!specification.IsSatisfiedBy(in context)) |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | internal static class UiModeGateSpecifications |
| 46 | { |
| 47 | // "Show telemetry hidden hint only if Power + telemetry enabled + terminal hidden." |
| 48 | public static readonly IUiModeGateSpecification ShowTelemetryHiddenHint = new AndUiModeGateSpecification( |
| 49 | new UiModeFamilyGateSpecification(UiModeFamily.Power), |
| 50 | new TelemetryEnabledGateSpecification(), |
| 51 | new TerminalHiddenGateSpecification()); |
| 52 | } |
| 53 | |