package node

import (
	"context"
	"net/http"

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

// RestrictRequest struct to set node status to 'RESTRICTED'
type RestrictRequest struct {
	// Node ID
	// Required: true
	NID uint64 `url:"nid" json:"nid" validate:"required"`

	// Migrate node
	// Default: false
	// Required: false
	Migrate bool `url:"migrate" json:"migrate"`
}

// Restrict sets node status to 'RESTRICTED' and migrates node if migrate=True
func (n Node) Restrict(ctx context.Context, req RestrictRequest) (string, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return "", validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/node/restrict"

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

	return string(res), nil
}
