package utilities

import (
	"context"
	"fmt"

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

func StackDataSourceCheckPresence(ctx context.Context, stackID uint64, c *client.Client) (*stack.InfoStack, error) {
	tflog.Info(ctx, fmt.Sprintf("StackDataSourceCheckPresence: Get info about stack with ID - %v", stackID))

	record, err := c.CloudBroker().Stack().Get(ctx, stack.GetRequest{StackId: stackID})
	if err != nil {
		return nil, fmt.Errorf("cannot get info about stack with error: %w", err)
	}

	tflog.Info(ctx, "StackDataSourceCheckPresence: response from CloudBroker().Stack().Get",
		map[string]any{"stack_id": stackID, "response": record})

	return record, err
}
