package node

import (
	"context"
	"net/http"
	"strconv"

	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)

// GetLogicalCoresCountRequest struct to get logical cores count by node
type GetLogicalCoresCountRequest struct {
	// Node ID
	// Required: true
	NodeId uint64 `url:"node_id" json:"node_id" validate:"required"`

	// Target
	// Required: false
	Target string `url:"target,omitempty" json:"target,omitempty" validate:"omitempty,oneof=core node"`
}

// GetLogicalCoresCount get logical cores count by node
func (i Node) GetLogicalCoresCount(ctx context.Context, req GetLogicalCoresCountRequest) (uint64, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return 0, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/get_logical_cores_count"

	res, err := i.client.DecortApiCall(ctx, http.MethodGet, url, req)
	if err != nil {
		return 0, err
	}

	result, err := strconv.ParseUint(string(res), 10, 64)
	if err != nil {
		return 0, err
	}

	return result, nil
}
