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

namespace Shared.Rcl.Commands.Routers;

public class RouterSetSettings : ServerNameSettings {
    [CommandOption("--Model")] public string Model { get; set; } = default!;

    [CommandOption("--managed")] public bool Managed { get; set; }

    [CommandOption("--poe")] public bool Poe { get; set; }
}

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

        await useCase.ExecuteAsync(
            settings.Name,
            settings.Model,
            settings.Managed,
            settings.Poe);

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