using System.ComponentModel;
using Microsoft.Extensions.DependencyInjection;
using RackPeek.Domain.Resources.AccessPoints;
using Shared.Rcl.Commands.Servers;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Shared.Rcl.Commands.AccessPoints;

public class AccessPointSetSettings : ServerNameSettings {
    [CommandOption("--model")]
    [Description("The access point model name.")]
    public string? Model { get; set; }

    [CommandOption("--speed")]
    [Description("The speed of the access point in Gb.")]
    public double? Speed { get; set; }
}

public class AccessPointSetCommand(
    IServiceProvider serviceProvider
) : AsyncCommand<AccessPointSetSettings> {
    protected override async Task<int> ExecuteAsync(
        CommandContext context,
        AccessPointSetSettings settings,
        CancellationToken cancellationToken) {
        using IServiceScope scope = serviceProvider.CreateScope();
        UpdateAccessPointUseCase useCase = scope.ServiceProvider.GetRequiredService<UpdateAccessPointUseCase>();

        await useCase.ExecuteAsync(
            settings.Name,
            settings.Model,
            settings.Speed
        );

        AnsiConsole.MarkupLine($"[green]Access Point '{settings.Name}' updated.[/]");
        return 0;
    }
}
