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"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/account/models"
)

func AccountReservedUnitsCheck(ctx context.Context, plan *models.DataSourceAccountReservedUnitsModel, c *client.Client) (*account.ResourceLimits, error) {
	tflog.Info(ctx, "AccountReservedUnitsCheck: Get info about account units")

	req := account.GetReservedAccountUnitsRequest{
		AccountID: uint64(plan.AccountID.ValueInt64()),
	}

	tflog.Info(ctx, "AccountReservedUnitsCheck: before call CloudAPI().Account().GetReservedAccountUnits", map[string]any{"req": req})
	accountUnits, err := c.CloudAPI().Account().GetReservedAccountUnits(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about account units: %w", err)
	}

	tflog.Info(ctx, "AccountReservedUnitsCheck: response from CloudAPI().Account().GetReservedAccountUnits")

	return accountUnits, err
}
