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/k8ci"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
)

func K8ciDataSourceCheckPresence(ctx context.Context, k8ciID uint64, c *client.Client) (*k8ci.RecordK8CI, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("K8ciDataSourceCheckPresence: Get info about k8ci with ID - %v", k8ciID))

	diags := diag.Diagnostics{}

	recordK8ci, err := c.CloudBroker().K8CI().Get(ctx, k8ci.GetRequest{K8CIID: k8ciID})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about k8ci with ID %v", k8ciID), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "K8ciDataSourceCheckPresence: response from CloudBroker().K8CI().Get", map[string]any{"k8ci_id": k8ciID, "response": recordK8ci})

	return recordK8ci, nil
}
