using Microsoft.Extensions.DependencyInjection; namespace LanMountainDesktop.AirAppSdk; /// /// Extension methods for registering AirApp services. /// public static class AirAppServiceCollectionExtensions { /// /// Register a desktop component. /// public static IServiceCollection AddAirAppComponent( this IServiceCollection services, string id, string name, Action? configure = null) where TWidget : class, IAirAppWidget { var options = new AirAppComponentOptions { Id = id, Name = name, WidgetType = typeof(TWidget) }; configure?.Invoke(options); // Register the widget as transient (new instance per placement) services.AddTransient(); // Register the component options (will be picked up by the host) services.AddSingleton(options); return services; } /// /// Register a window. /// public static IServiceCollection AddAirAppWindow( this IServiceCollection services, string id, string name) where TWindow : class, IAirAppWindow { // Register the window as transient (new instance per open) services.AddTransient(); // TODO: Register window metadata return services; } /// /// Register a settings section (declarative). /// public static IServiceCollection AddAirAppSettings( this IServiceCollection services, string id, string name, Action? configure = null) { var builder = new AirAppSettingsSectionBuilder(id, name); configure?.Invoke(builder); // Register the settings section services.AddSingleton(builder.Build()); return services; } } /// /// Builder for settings sections. /// public sealed class AirAppSettingsSectionBuilder { private readonly string _id; private readonly string _name; private readonly List _options = new(); internal AirAppSettingsSectionBuilder(string id, string name) { _id = id; _name = name; } public AirAppSettingsSectionBuilder AddToggle(string key, string label, bool defaultValue = false) { _options.Add(new AirAppSettingOption { Key = key, Label = label, Type = "toggle", DefaultValue = defaultValue }); return this; } public AirAppSettingsSectionBuilder AddText(string key, string label, string? defaultValue = null) { _options.Add(new AirAppSettingOption { Key = key, Label = label, Type = "text", DefaultValue = defaultValue }); return this; } public AirAppSettingsSectionBuilder AddNumber(string key, string label, double defaultValue = 0, double? minimum = null, double? maximum = null) { _options.Add(new AirAppSettingOption { Key = key, Label = label, Type = "number", DefaultValue = defaultValue, Minimum = minimum, Maximum = maximum }); return this; } internal AirAppSettingsSection Build() { return new AirAppSettingsSection { Id = _id, Name = _name, Options = _options }; } } /// /// Settings section metadata. /// public sealed class AirAppSettingsSection { public required string Id { get; init; } public required string Name { get; init; } public required List Options { get; init; } } /// /// Individual setting option. /// public sealed class AirAppSettingOption { public required string Key { get; init; } public required string Label { get; init; } public required string Type { get; init; } public object? DefaultValue { get; init; } public double? Minimum { get; init; } public double? Maximum { get; init; } }