package utilities

import (
	"context"
	"fmt"

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

func BServiceGroupDataSourceCheckPresence(ctx context.Context, state models.RecordGroupModel, c *client.Client) (*bservice.RecordGroup, error) {
	tflog.Info(ctx, fmt.Sprintf("BServiceGroupDataSourceCheckPresence: Get info about bserivce  with  ID - %v", state.ServiceID))

	req := bservice.GroupGetRequest{ServiceID: uint64(state.ServiceID.ValueInt64()), CompGroupID: uint64(state.ID.ValueInt64())}

	record, err := c.CloudAPI().BService().GroupGet(ctx, req)

	if err != nil {
		return nil, fmt.Errorf("cannot get info about bservice with error: %w", err)
	}

	return record, err
}
