package views

import (
	"fmt"
	"strconv"

	"awesome_cli/internal/entity"
	"awesome_cli/internal/ui"
)

func List(vms []entity.VirtualMachineOutput) {
	var runCount int

	t := ui.NewTableBuilder()
	t.AddTableHeader("Status", "Name", "vCPU", "Memory", "Datastore")
	for _, vm := range vms {
		t.AddRow(
			vm.Status.String(),
			vm.Name,
			strconv.FormatInt(int64(vm.CPU), 10),
			strconv.FormatInt(int64(vm.Memory), 10),
			vm.DatastoreName,
		)
		if vm.Status == entity.Running {
			runCount++
		}
	}

	header := ui.Header("Virtual machines")
	count := ui.Info(fmt.Sprintf("Total: %d", len(vms)))
	running := ui.Info(fmt.Sprintf("Run: %d", runCount))

	fmt.Printf("%s\n\n", ui.StringBar(header, count, running))
	fmt.Println(t.CreateTable())
}
