package account import ( "context" "encoding/json" "net/http" "repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators" ) // DeleteAccountsRequest struct to delete group of accounts type DeleteAccountsRequest struct { // IDs of accounts // Required: true AccountsIDs []uint64 `url:"accountIds" json:"accountIds" validate:"min=1"` // Whether to completely destroy accounts or not // Required: false Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"` } type wrapperDeleteAccountsRequest struct { DeleteAccountsRequest AsyncMode bool `url:"async_mode" json:"async_mode"` } // DeleteAccounts destroys a group of accounts func (a Account) DeleteAccounts(ctx context.Context, req DeleteAccountsRequest) ([]uint64, error) { err := validators.ValidateRequest(req) if err != nil { return nil, validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/account/deleteAccounts" reqWrapped := wrapperDeleteAccountsRequest{ DeleteAccountsRequest: req, AsyncMode: false, } res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped) if err != nil { return nil, err } result := make([]uint64, 0) err = json.Unmarshal(res, &result) if err != nil { return nil, err } return result, nil } // DeleteAccountsAsync destroys a group of accounts in async mode func (a Account) DeleteAccountsAsync(ctx context.Context, req DeleteAccountsRequest) (string, error) { err := validators.ValidateRequest(req) if err != nil { return "", validators.ValidationErrors(validators.GetErrors(err)) } url := "/cloudbroker/account/deleteAccounts" reqWrapped := wrapperDeleteAccountsRequest{ DeleteAccountsRequest: req, AsyncMode: true, } res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, reqWrapped) if err != nil { return "", err } return string(res), nil }