package bservice

import (
	"context"

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

func existRGID(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
	c := m.(*controller.ControllerCfg)

	req := rg.ListRequest{}

	rgList, err := c.CloudAPI().RG().List(ctx, req)
	if err != nil {
		return false, err
	}

	rgId := uint64(d.Get("rg_id").(int))

	return len(rgList.FilterByID(rgId).Data) != 0, nil
}
