package rg

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

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

// DeleteACLAccessRequest deletes ACL access from a resource group
type DeleteACLAccessRequest struct {
	ID          uint64   `url:"id"          json:"id" validate:"required"`
	Usernames   []string `url:"usernames,omitempty"   json:"usernames,omitempty"`
	APIAccesses []uint64 `url:"apiaccesses,omitempty" json:"apiaccesses,omitempty"`
}

// DeleteACLAccess deletes ACL access from a resource group.
func (r RG) DeleteACLAccess(ctx context.Context, req DeleteACLAccessRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/rg/del_acl_access"

	res, err := r.client.DecortApiCallCtype(ctx, http.MethodPost, 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
}
