package acsgroups

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

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

// DeleteRequest struct to delete access group
type DeleteRequest struct {
	// ID of the access group
	// Required: true
	GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
}

// Delete a access groups
func (i AccessGroups) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/sdn/access_group/delete"

	res, err := i.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
	if err != nil {
		return false, err
	}

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

	return result, nil
}
