using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; namespace ClawdDotNet.Desktop.ViewModels; public sealed record AddServiceResultData( string ServiceName, string ServiceType, int ServicePort, string ServiceDescription ); public sealed partial class AddServiceViewModel : ViewModelBase { [ObservableProperty] private string _serviceName = ""; [ObservableProperty] private string _serviceType = "HTTP"; [ObservableProperty] private int _servicePort = 8080; [ObservableProperty] private string _serviceDescription = ""; [ObservableProperty] private string _statusMessage = ""; public List AvailableServiceTypes { get; } = ["HTTP", "TCP", "gRPC", "WebSocket", "Custom"]; public AddServiceResultData? Result { get; private set; } public event Action? CloseRequested; [RelayCommand] private void Confirm() { if (string.IsNullOrWhiteSpace(ServiceName)) { StatusMessage = "Please enter a service name."; return; } if (ServicePort <= 0 || ServicePort > 65535) { StatusMessage = "Please enter a valid port between 1 and 65535."; return; } Result = new AddServiceResultData( ServiceName.Trim(), ServiceType, ServicePort, ServiceDescription.Trim() ); CloseRequested?.Invoke(); } [RelayCommand] private void Cancel() { Result = null; CloseRequested?.Invoke(); } }