package utilities

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/rg/models"
)

func RGAuditsCheckPresence(ctx context.Context, plan *models.DataSourceRGAuditsModel, c *client.Client) (*rg.ListAudits, error) {
	auditsReq := rg.AuditsRequest{
		RGID: uint64(plan.RGID.ValueInt64()),
	}

	tflog.Info(ctx, "RGAuditsCheckPresence: before call CloudAPI().RG().Audits", map[string]any{"response": auditsReq})
	rgAudtis, err := c.CloudAPI().RG().Audits(ctx, auditsReq)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about resource group audits with error: %w", err)
	}

	tflog.Info(ctx, "RGAuditsCheckPresence: response from CloudAPI().RG().Audits", map[string]any{"response": rgAudtis})

	return &rgAudtis, err
}
