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 utilityRgAffinityGroupComputesCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (rg.ListAffinityGroupCompute, error) {
	c := m.(*controller.ControllerCfg)
	req := rg.AffinityGroupComputesRequest{
		RGID:          uint64(d.Get("rg_id").(int)),
		AffinityGroup: d.Get("affinity_group").(string),
	}

	log.Debugf("utilityRgAffinityGroupComputesCheckPresence: load affinity group computes")
	res, err := c.CloudBroker().RG().AffinityGroupComputes(ctx, req)
	if err != nil {
		return nil, err
	}

	return res, nil
}
