package account

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

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

// DelACLAccessRequest deletes ACL access from an account
type DelACLAccessRequest 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"`
}

// DelACLAccess deletes ACL access from an account.
func (a Account) DeleteACLAccess(ctx context.Context, req DelACLAccessRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/account/del_acl_access"

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