package utilities

import (
	"context"
	"fmt"

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

func NodeDataSourceCheckPresence(ctx context.Context, nodeId uint64, c *client.Client) (*node.RecordNode, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("NodeDataSourceCheckPresence: Get info about Node with ID - %v", nodeId))

	diags := diag.Diagnostics{}

	recordNode, err := c.CloudBroker().Node().Get(ctx, node.GetRequest{NID: nodeId})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about Node with ID %v", nodeId), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "NodeDataSourceCheckPresence: response from loudBroker().Node().Get", map[string]any{"node_id": nodeId, "response": recordNode})

	return recordNode, nil
}
