package vins

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

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

// UpdateRequest struct to update vins parameters
type UpdateRequest struct {
	// VINS ID
	// Required: true
	VINSID uint64 `url:"vins_id" json:"vins_id" validate:"required"`

	// Name
	// Required: false
	Name string `url:"name,omitempty" json:"name,omitempty"`

	// Desc
	// Required: false
	Desc string `url:"desc,omitempty" json:"desc,omitempty"`

	// Flag indicating whether security groups are enabled for this network
	// Required: false
	EnableSecGroups interface{} `url:"enable_secgroups,omitempty" json:"enable_secgroups,omitempty" validate:"omitempty,isBool"`
}

// Update updates a vins parameters
func (v VINS) Update(ctx context.Context, req UpdateRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/vins/update"

	res, err := v.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

}
