package user

import (
	"context"
	"encoding/json"
	"net/http"
)

// GetResourceConsumption gets amount of consumed and reserved resources (cpu, ram, disk) by current user
func (u User) GetResourceConsumption(ctx context.Context) (*ResourceConsumption, error) {
	url := "/cloudapi/user/getResourceConsumption"

	res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, nil)
	if err != nil {
		return nil, err
	}

	item := ResourceConsumption{}

	err = json.Unmarshal(res, &item)
	if err != nil {
		return nil, err
	}

	return &item, nil
}
