package utilities

import (
	"context"
	"fmt"

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

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

	tflog.Info(ctx, "RGGetResourceConsumptionCheckPresence: before call CloudBroker().RG().GetResourceConsumption", map[string]any{"response": resConsReq})
	resCons, err := c.CloudBroker().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 CloudBroker().RG().GetResourceConsumption", map[string]any{"response": resCons})

	return resCons, err
}
