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

func AuditDataSourceCheckPresence(ctx context.Context, auditGuid string, c *client.Client) (*audit.RecordAudit, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("AuditDataSourceCheckPresence: Get info about audit with ID - %v", auditGuid))

	diags := diag.Diagnostics{}

	recordAudit, err := c.CloudBroker().Audit().Get(ctx, audit.GetRequest{AuditGuid: auditGuid})
	if err != nil {
		diags.AddError(fmt.Sprintf("Cannot get info about audit with ID %v", auditGuid), err.Error())
		return nil, diags
	}

	tflog.Info(ctx, "AuditDataSourceCheckPresence: response from CloudBroker().Audit().Get", map[string]any{"audit_guid": auditGuid, "response": recordAudit})

	return recordAudit, nil
}
