package node

import (
	"context"
	"net/http"

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

// UpdateRequest struct to update node for actual version
type UpdateRequest struct {
	// List of Node IDs
	// Required: true
	NID uint64 `url:"nid" json:"nid" validate:"required"`
}

// Update updates node for actual version
func (n Node) Update(ctx context.Context, req UpdateRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/update"

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

	return string(res), nil
}
