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

func VINSAuditsDataSourceCheckPresence(ctx context.Context, vinsId uint64, c *client.Client) (*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.CloudAPI().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: successfull response from CloudAPI().VINS().Audits", map[string]any{"vins_id": vinsId})

	return &audits, nil
}
