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

func LBDataSourceCheckPresence(ctx context.Context, lbId uint64, c *client.Client) (*lb.RecordLB, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("LBDataSourceCheckPresence: Get info about lb with ID - %v", lbId))

	diags := diag.Diagnostics{}

	recordLB, err := c.CloudBroker().LB().Get(ctx, lb.GetRequest{LBID: lbId})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about lb with ID %v", lbId), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "LBDataSourceCheckPresence: response from CloudBroker().LB().Get", map[string]any{"lb_id": lbId, "response": recordLB})

	return recordLB, nil
}
