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

func DPDKDataSourceCheckPresence(ctx context.Context, dpdkId uint64, c *client.Client) (*dpdknet.RecordDPDKNet, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("DPDKDataSourceCheckPresence: Get info about DPDK net with ID - %d", dpdkId))

	diags := diag.Diagnostics{}

	recordDPDK, err := c.CloudAPI().DPDKNet().Get(ctx, dpdknet.GetRequest{DPDKID: dpdkId})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about DPDK net with ID %d", dpdkId), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "DPDKDataSourceCheckPresence: response from CloudBroker().DPDKNet().Get", map[string]any{"dpdk_id": dpdkId, "response": recordDPDK})

	return recordDPDK, nil
}
