package utilities

import (
	"context"
	"fmt"

	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/client"
	"repository.basistech.ru/BASIS/terraform-provider-dynamix/internal/service/cloudapi/rg/models"

	"github.com/hashicorp/terraform-plugin-log/tflog"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudapi/rg"
)

func RGAffinityGroupComputesCheckPresence(ctx context.Context, plan *models.DataSourceRGAffinityGroupComputesModel, c *client.Client) (*rg.ListAffinityGroupsComputes, error) {
	agCompsReq := rg.AffinityGroupComputesRequest{
		RGID:          uint64(plan.RGID.ValueInt64()),
		AffinityGroup: plan.AffinityGroup.ValueString(),
	}

	tflog.Info(ctx, "RGAffinityGroupComputesCheckPresence: before call CloudAPI().RG().AffinityGroupComputes", map[string]any{"req": agCompsReq})
	agCompsList, err := c.CloudAPI().RG().AffinityGroupComputes(ctx, agCompsReq)
	if err != nil {
		return nil, fmt.Errorf("cannot get info about resource group affinity group computes with error: %w", err)
	}

	tflog.Info(ctx, "RGAffinityGroupComputesCheckPresence: response from CloudAPI().RG().AffinityGroupComputes", map[string]any{"response": agCompsList})

	return &agCompsList, err
}
