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 LaptopGpuAddCommand(IServiceProvider provider)
    : AsyncCommand<LaptopGpuAddSettings> {
    protected override async Task<int> ExecuteAsync(
        CommandContext context,
        LaptopGpuAddSettings settings,
        CancellationToken cancellationToken) {
        using IServiceScope scope = provider.CreateScope();
        IAddGpuUseCase<Laptop> useCase = scope.ServiceProvider.GetRequiredService<IAddGpuUseCase<Laptop>>();

        await useCase.ExecuteAsync(settings.LaptopName, settings.Model, settings.Vram);

        AnsiConsole.MarkupLine($"[green]GPU added to Laptop '{settings.LaptopName}'.[/]");
        return 0;
    }
}
