package rg

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

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

// AccessRevokeRequest struct to revoke access
type AccessRevokeRequest struct {
	// Resource group ID
	// Required: true
	RGID uint64 `url:"rgId" json:"rgId" validate:"required"`

	// User or group name to revoke access
	// Required: true
	User string `url:"user" json:"user" validate:"required"`
}

// AccessRevoke revokes specified user or group access from the resource group
//
// Deprecated: will be removed in SDK v1.17
func (r RG) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/rg/accessRevoke"

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