package utilities

import (
	"context"
	"fmt"

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

func AccountConsumedUnitsByTypeDataSourceCheckPresence(ctx context.Context, accountId uint64, cuType string, c *client.Client) (float64, error) {
	tflog.Info(ctx, fmt.Sprintf("AccountConsumedUnitsByTypeDataSourceCheckPresence: Get info about account with ID - %v", accountId))

	req := account.GetConsumedCloudUnitsByTypeRequest{
		AccountID: accountId,
		CUType:    cuType,
	}

	tflog.Info(ctx, "AccountConsumedUnitsByTypeDataSourceCheckPresence: before call to from CloudAPI().Account().GetConsumedCloudUnitsByType",
		map[string]any{"account_id": accountId, "req": req})

	res, err := c.CloudAPI().Account().GetConsumedCloudUnitsByType(ctx, req)
	if err != nil {
		return 0, fmt.Errorf("cannot get info about account consumed units by type with error: %w", err)
	}

	tflog.Info(ctx, "AccountConsumedUnitsByTypeDataSourceCheckPresence: response from CloudAPI().Account().GetConsumedCloudUnitsByType",
		map[string]any{"account_id": accountId, "response": res})

	return res, err
}
