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

func VINSDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *client.Client) (*vins.RecordVINS, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("VINSDataSourceCheckPresence: Get info about vins with ID - %v", vinsId))

	diags := diag.Diagnostics{}

	recordVINS, err := c.CloudBroker().VINS().Get(ctx, vins.GetRequest{VINSID: vinsId})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about vins with ID %v", vinsId), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "VINSDataSourceCheckPresence: response from CloudBroker().VINS().Get", map[string]any{"vins_id": vinsId, "response": recordVINS})

	return recordVINS, nil
}
