using Microsoft.Extensions.DependencyInjection;
using RackPeek.Domain.Resources.Servers;
using RackPeek.Domain.UseCases.Cpus;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Shared.Rcl.Commands.Servers.Cpus;

public class ServerCpuRemoveSettings : ServerNameSettings {
    [CommandOption("--index <INDEX>")] public int Index { get; set; }
}

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

        await useCase.ExecuteAsync(
            settings.Name,
            settings.Index);

        AnsiConsole.MarkupLine($"[green]CPU {settings.Index} removed from '{settings.Name}'.[/]");
        return 0;
    }
}
