package rg

import (
	"context"
	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/dc"
	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/service/cloudbroker/ic"

	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

	"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)

func checkParamsExistence(ctx context.Context, d *schema.ResourceData, c *controller.ControllerCfg, accountId, gid uint64) diag.Diagnostics {
	var errs []error

	if err := ic.ExistAccount(ctx, accountId, c); err != nil {
		errs = append(errs, err)
	}

	if err := ic.ExistGID(ctx, gid, c); err != nil {
		errs = append(errs, err)
	}

	extNetId, ok := d.GetOk("ext_net_id")
	if ok {
		if err := ic.ExistExtNetInRG(ctx, uint64(extNetId.(int)), accountId, c); err != nil {
			errs = append(errs, err)
		}
	}
	return dc.ErrorsToDiagnostics(errs)
}
