package sep

import (
	"context"
	"encoding/json"
	"net/http"

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

// AddConsumerNodesRequest struct to add consumer nodes
type AddConsumerNodesRequest struct {
	// Storage endpoint provider ID
	// Required: true
	SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`

	// List of nodes IDs
	// Required: true
	ConsumerNIDs []uint64 `url:"consumer_nids" json:"consumer_nids" validate:"min=1"`
}

// AddConsumerNodes adds consumer nodes to SEP parameters
func (s SEP) AddConsumerNodes(ctx context.Context, req AddConsumerNodesRequest) ([]uint64, error) {
	err := validators.ValidateRequest(req)
	list := []uint64{}
	if err != nil {
		return list, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/sep/addConsumerNodes"

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

	err = json.Unmarshal(res, &list)
	if err != nil {
		return nil, err
	}

	return list, nil
}
