package utilities

import (
	"context"
	"fmt"

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

func RGUsageCheckPresence(ctx context.Context, plan *models.DataSourceRGUsageModel, c *client.Client) (*rg.RecordResourceUsage, error) {
	usageReq := rg.UsageRequest{RGID: uint64(plan.RGID.ValueInt64())}

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

	tflog.Info(ctx, "RGUsageCheckPresence: response from CloudAPI().RG().Usage", map[string]any{"response": usage})

	return usage, err
}
