package rg

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
	log "github.com/sirupsen/logrus"
	"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)

func utilityRgAffinityGroupsGetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) ([]uint64, error) {
	c := m.(*controller.ControllerCfg)
	req := rg.AffinityGroupsGetRequest{
		RGID:          uint64(d.Get("rg_id").(int)),
		AffinityGroup: d.Get("affinity_group").(string),
	}

	log.Debugf("utilityRgAffinityGroupsGetCheckPresence: load computes in the specified affinity group")
	computes, err := c.CloudBroker().RG().AffinityGroupsGet(ctx, req)
	if err != nil {
		return nil, err
	}

	return computes, nil
}
