package zone

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

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

// DelNodeRequest struct to remove node from zone
type DelNodeRequest struct {
	// ID of zone
	// Required: true
	ID uint64 `url:"id" json:"id" validate:"required"`

	// List of node ids
	// Required: true
	NodeIDs []uint64 `url:"nodeIds" json:"nodeIds" validate:"required"`
}

// DelNode remove nodes from zone
func (e Zone) DelNode(ctx context.Context, req DelNodeRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/zone/delNode"

	res, err := e.client.DecortApiCall(ctx, http.MethodPost, url, req)

	if err != nil {
		return false, err
	}

	result, err := strconv.ParseBool(string(res))
	if err != nil {
		return false, err
	}

	return result, nil
}
