package node

import (
	"context"
	"net/http"

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

// SetHugePagesRequest struct to set on-boot Huge Pages configuration
type SetHugePagesRequest struct {
	// Node ID
	// Required: true
	NID uint64 `url:"nid" json:"nid" validate:"required"`

	// Number of 2M hugepages to claim
	// Required: true
	HugePages2M uint64 `url:"hugepages2M" json:"hugepages2M" validate:"required"`

	// Number of 1G hugepages to claim
	// Required: true
	HugePages1G uint64 `url:"hugepages1G" json:"hugepages1G" validate:"required"`
}

// SetHugePages sets on-boot Huge Pages configuration
func (n Node) SetHugePages(ctx context.Context, req SetHugePagesRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/setHugePages"

	res, err := n.client.DecortApiCall(ctx, http.MethodPost, url, req)
	if err != nil {
		return "", err
	}

	return string(res), nil
}
