package utilities

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-framework/diag"
	"github.com/hashicorp/terraform-plugin-log/tflog"
	decort "repository.basistech.ru/BASIS/decort-golang-sdk"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
)

func VINSAuditsDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *decort.DecortClient) (*vins.ListAudits, diag.Diagnostics) {
	tflog.Info(ctx, fmt.Sprintf("VINSAuditsDataSourceCheckPresence: Get info about vins audit with vins ID - %v", vinsId))

	diags := diag.Diagnostics{}

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

	tflog.Info(ctx, "VINSAuditsDataSourceCheckPresence: successful response from CloudBroker().VINS().Audits", map[string]any{"vins_id": vinsId})

	return &audits, nil
}
