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 RGAffinityGroupsGetCheckPresence(ctx context.Context, plan *models.DataSourceRGAffinityGroupsGetModel, c *client.Client) ([]uint64, error) {
	agReq := rg.AffinityGroupsGetRequest{
		RGID:          uint64(plan.RGID.ValueInt64()),
		AffinityGroup: plan.AffinityGroup.ValueString(),
	}

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

	tflog.Info(ctx, "RGAffinityGroupsGetCheckPresence: response from CloudAPI().RG().AffinityGroupsGet", map[string]any{"response": agItem})

	return agItem, err
}
