package utilities

import (
	"context"
	"fmt"

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

func StackCheckPresence(ctx context.Context, stackID uint64, c *client.Client) (*stack.InfoStack,
	error) {
	req := stack.GetRequest{
		StackId: stackID,
	}

	tflog.Info(ctx, "StackCheckPresence: before call CloudAPI().Stack().Get", map[string]any{"req": req})
	stack, err := c.CloudAPI().Stack().Get(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about stack with error: %w", err)
	}

	tflog.Info(ctx, "StackCheckPresence: response from CloudAPI().Stack().Get", map[string]any{"response": stack})

	return stack, err
}
