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

namespace Shared.Rcl.Commands.Servers.Gpus;

public class ServerGpuAddSettings : ServerNameSettings {
    [CommandOption("--model <MODEL>")] public string? Model { get; set; }

    [CommandOption("--vram <VRAM>")] public int Vram { get; set; }
}

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

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

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