using Microsoft.Extensions.DependencyInjection;
using RackPeek.Domain.Resources.Laptops;
using RackPeek.Domain.UseCases.Gpus;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Shared.Rcl.Commands.Laptops.Gpus;

public class LaptopGpuRemoveCommand(IServiceProvider provider)
    : AsyncCommand<LaptopGpuRemoveSettings> {
    protected override async Task<int> ExecuteAsync(
        CommandContext context,
        LaptopGpuRemoveSettings settings,
        CancellationToken cancellationToken) {
        using IServiceScope scope = provider.CreateScope();
        IRemoveGpuUseCase<Laptop> useCase = scope.ServiceProvider.GetRequiredService<IRemoveGpuUseCase<Laptop>>();

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

        AnsiConsole.MarkupLine($"[green]GPU #{settings.Index} removed from Laptop '{settings.LaptopName}'.[/]");
        return 0;
    }
}
