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 AuditLinkedJobsDataSourceCheckPresence(ctx context.Context, auditGuid string, c *client.Client) (*audit.ListLinkedJobs, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("AuditLinkedJobsDataSourceCheckPresence: Get info about audit linked jobs with ID - %v", auditGuid))

	diags := diag.Diagnostics{}

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

	tflog.Info(ctx, "AuditLinkedJobsDataSourceCheckPresence: response from CloudBroker().Audit().LinkedJobs", map[string]any{"audit_guid": auditGuid, "response": linkedJobsList})

	return linkedJobsList, nil
}
