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 RGUsageCheckPresence(ctx context.Context, plan *models.DataSourceRGUsageModel, c *client.Client) (*rg.Reservation, error) {
	usageReq := rg.UsageRequest{RGID: uint64(plan.RGID.ValueInt64())}

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

	return usage, err
}
