package utilities

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-log/tflog"
	decort "repository.basistech.ru/BASIS/decort-golang-sdk"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/rg/models"
)

func RGGetResourceConsumptionCheckPresence(ctx context.Context, plan *models.DataSourceRGGetResourceConsumptionModel, c *decort.DecortClient) (*rg.ItemResourceConsumption, error) {
	resConsReq := rg.GetResourceConsumptionRequest{RGID: uint64(plan.RGID.ValueInt64())}

	tflog.Info(ctx, "RGGetResourceConsumptionCheckPresence: before call CloudAPI().RG().GetResourceConsumption", map[string]any{"response": resConsReq})
	resCons, err := c.CloudAPI().RG().GetResourceConsumption(ctx, resConsReq)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about resource group get resource consumption with error: %w", err)
	}

	tflog.Info(ctx, "RGGetResourceConsumptionCheckPresence: response from CloudAPI().RG().GetResourceConsumption", map[string]any{"response": resCons})

	return resCons, err
}
